制作工資條是每位财務從業者必備技能,今天教大家如何用Excel VBA一鍵制作工資條。
工資表數據
思路
1、用Union方法,将表頭和标題欄聯合到一起,賦值為Rng。
2、循環工資表,再用Union方法,将每行數據和Rng聯合到一起,複制到工資條工作表。
自動生成工資條
代碼
Private Sub CommandButton1_Click()
On Error Resume Next
Dim i%, j%, rng As Range, ws As Worksheet
Set ws = Sheets(工資表)
Set rng = Union(ws.Rows(1), ws.Rows(2), ws.Rows(3)) 表頭及标題欄
Sheets(工資條).Cells.Clear
j = 1
Application.ScreenUpdating = False
With Sheets(工資條)
For i = 4 To ws.Cells(Rows.Count, 1).End(xlUp).Row
Union(rng, ws.Rows(i)).Copy .Cells(j, 1)
j = j 4
Next i
End With
MsgBox 工資條制作完成!
Application.ScreenUpdating = True
End Sub
,
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!