'将表2的数据追加到表1中
Public Sub CopySheet2Rows()
Dim x As Integer, FinalRow As Integer, NextRow As Integer
Dim sh_src As Worksheet
Dim sh_dst As Worksheet
Set sh_src = ThisWorkbook.Worksheets("2")
Set sh_dst = ThisWorkbook.Worksheets("1")
' Find the last row of data
FinalRow = sh_src.Cells(sh_src.Rows.Count, 1).End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column D
If Not IsEmpty(sh_src.Cells(x, 4)) Then
sh_src.Cells(x, 1).Resize(1, 12).Copy
'Sheets("SheetA").Select
NextRow = sh_dst.Cells(sh_dst.Rows.Count, 1).End(xlUp).Row + 1
sh_dst.Cells(NextRow, 1).Select
sh_dst.Paste
End If
Next x
End Sub
[此贴子已经被作者于2023-10-19 15:34编辑过]