|
换一种方式,避开copy,工资表什么样的格式也不受影响。- Public Function SheetExist(ByVal ShName As String) As Boolean
- Dim WSh As Worksheet
- SheetExist = False
- For Each WSh In ThisWorkbook.Worksheets
- If WSh.Name = ShName Then
- SheetExist = True
- Exit For
- End If
- Next WSh
- End Function
- Public Sub CreateSalarySheet()
- Dim LastRow As Long, TempRow As Long
- Dim i As Long
- Dim arr1, arr2
- Dim rng As Range
- With Worksheets("工资表")
- LastRow = .Cells(65536, 2).End(xlUp).Row
- arr1 = .Range("a1").Resize(1, 11).Value
- arr2 = .Range("a2").Resize(LastRow - 1, 11).Value
- End With
- If SheetExist("工资条") = False Then
- ThisWorkbook.Worksheets().Add.Name = "工资条"
- Sheets("工资条").Range("a1").Resize(1, 11).ColumnWidth = 10.63
- Else
- Sheets("工资条").Range("a1").Resize(2000, 11).Clear
- End If
-
- TempRow = 1
- For i = 1 To LastRow - 1
- With Worksheets("工资条")
- Set rng = .Cells(TempRow, 1).Resize(2, 11)
- With rng
- .Cells(1, 1).Resize(1, 11) = arr1 '工资条目
- .Cells(2, 1).Resize(1, 11) = WorksheetFunction.Index(arr2, i, 0) '工资条内容
- '以下是设置每一个工资条的边框
- .Borders(xlEdgeLeft).LineStyle = xlContinuous
- .Borders(xlEdgeLeft).ColorIndex = xlAutomatic
- .Borders(xlEdgeLeft).Weight = xlMedium
-
- .Borders(xlEdgeTop).LineStyle = xlContinuous
- .Borders(xlEdgeTop).ColorIndex = xlAutomatic
- .Borders(xlEdgeTop).Weight = xlMedium
-
- .Borders(xlEdgeBottom).LineStyle = xlContinuous
- .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
- .Borders(xlEdgeBottom).Weight = xlMedium
-
- .Borders(xlEdgeRight).LineStyle = xlContinuous
- .Borders(xlEdgeRight).ColorIndex = xlAutomatic
- .Borders(xlEdgeRight).Weight = xlMedium
-
- .Borders(xlInsideVertical).LineStyle = xlContinuous
- .Borders(xlInsideVertical).ColorIndex = xlAutomatic
- .Borders(xlInsideVertical).Weight = xlThin
-
- .Borders(xlInsideHorizontal).LineStyle = xlContinuous
- .Borders(xlInsideHorizontal).ColorIndex = xlAutomatic
- .Borders(xlInsideHorizontal).Weight = xlThin
- End With
- End With
- TempRow = TempRow + 3 '下一位员工
- Next i
- End Sub
复制代码 |
|