|
Sub CopyAndTransferData()
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Set wsSource = ThisWorkbook.Sheets("欠费明细")
Set wsDest = ThisWorkbook.Sheets("缴费通知单")
Dim lastRow As Long
Dim i As Long
Dim n As Long
Dim copyCount As Long
' 计算SHEET1中A2以下的有内容的行数
lastRow = wsSource.Cells(wsSource.Rows.Count, 1).End(xlUp).Row
copyCount = lastRow - 1 ' 从A2开始计算
' 复制SHEET2的1到5行,复制次数为copyCount
For i = 1 To copyCount
wsDest.Rows("1:5").Copy Destination:=wsDest.Rows(5 * i + 1)
Next i
' 将SHEET1的第二行开始的内容录入SHEET2的3, 8, 13, ..., 3 + 5n
For i = 2 To lastRow
wsDest.Cells(3 + 5 * (i - 2), 1).Value = wsSource.Cells(i, 1).Value ' 修改列号以适应需要
Next i
End Sub
|
|