




=VLOOKUP($K2,$A$2:$G$19,COLUMN(B2),0)我们只需要做一个员工就行了。公式写完再设计一下格式。












Sub 标签拆分()Dim titlerng As Range, ws As Worksheet, titlecol%, titlerow%Dim lastrow%, i%, cell1$On Error Resume NextSet ws = ThisWorkbook.ActiveSheetSet titlerng = Application.InputBox("选定标题行区域", "标题行", Type:=8)If titlerng Is Nothing Then Err.Clear: EndOn Error GoTo 0Application.ScreenUpdating = Falselastrow = ws.Range("b65535").End(xlUp).Rowtitlecol = titlerng.Columns.Counttitlerow = titlerng.Rows.Countcell1 = titlerng.cells(1, 1)If cells.Find(what:=cell1, after:=ws.Range("a2")).Row > 2 ThenMsgBox "疑似存在多个标题行,已生成过工资条,无需再生成!", , "提示"EndEnd If'最后一条记录设置剪切线With ws.Range(ws.cells(lastrow + 1, 1), ws.cells(lastrow + 2, titlecol)).RowHeight = 8.Borders(xlEdgeLeft).LineStyle = xlNone.Borders(xlEdgeRight).LineStyle = xlNonews.Range(ws.cells(lastrow + 2, 1), ws.cells(lastrow + 2, titlecol)).Borders(xlEdgeTop).LineStyle = xlDashDot.Borders(xlInsideVertical).LineStyle = xlNoneEnd WithFor i = lastrow To titlerng.Rows.Count + 2 Step -1ws.Rows(i).Resize(titlerow + 2).Inserttitlerng.Copy ws.Range("a" & i + 2)'设置剪切线With ws.Range(ws.cells(i, 1), ws.cells(i + 1, titlecol)).RowHeight = 8.Borders(xlEdgeLeft).LineStyle = xlNone.Borders(xlEdgeRight).LineStyle = xlNonews.Range(ws.cells(i + 1, 1), ws.cells(i + 1, titlecol)).Borders(xlEdgeTop).LineStyle = xlDashDot.Borders(xlInsideVertical).LineStyle = xlNoneEnd WithNextApplication.ScreenUpdating = TrueMsgBox "拆分完成", , "完成"End SubSub 恢复数据原型()Dim header As Range, lastrow%, i%Dim ws As Worksheet, headerrow%Dim cell1$, cell2$On Error Resume NextSet ws = ThisWorkbook.ActiveSheetSet header = Application.InputBox("选择标题行", "标题行", Type:=8)Application.ScreenUpdating = FalseIf header Is Nothing Then Err.Clear: EndOn Error GoTo 0headerrow = header.Rows.Countlastrow = ws.Range("b56654").End(xlUp).Rowcell1 = header.cells(1, 1)cell2 = header.cells(1, 2)For i = headerrow + 1 To lastrowIf ws.Range("a" & i) = cell1 And ws.Range("b" & i) = cell2 Thenws.Range("a" & i).EntireRow.DeleteEnd IfNextws.Range("a" & headerrow + 1 & ":a" & lastrow).SpecialCells(Type:=xlCellTypeBlanks).EntireRow.DeleteApplication.ScreenUpdating = TrueEnd Sub
如果你想“从入门到精通”学习EXCEL,老师推荐以下两个教程:
关注我,学习更多高效办公技巧!
#办公技能#办公软件#职场技能#职场办公#wps#VBA#EXCEL函数
关注老师,点底部头像到主页,点右上角“…”,设为星标,才不错容易过精彩教程哦。

往期干货文章学习推荐:
Office2021专业版安装教程及安装包【已激活免费下载】
WPS打开宏文件提示“无权限”及宏“被禁止”怎么办?【插件限时领取】
【工具限时领取】用OUTLOOK轻松实现不同人不同内容的邮件群发
你还要手工加班算考勤?!1秒完成百人考勤,HR熬夜加班终结者
分享高效办公技巧及免费自动化模版,避免以后需要找不到,请您持续关注哦