要解決本例中的問題,可以將過程改寫為:
Sub 合并多表數(shù)據(jù)()
Dim EndRow As Long, DataArr As Variant, ToRng As Range
Dim ToSht As Worksheet, Sht As Worksheet
Set ToSht = Worksheets("匯總結(jié)果") '變量ToSht是保存匯總結(jié)果的工作表
ToSht.Rows("2:1048576").Clear '清除表中原有數(shù)據(jù)
Dim EndCol As Long '保存合并區(qū)域的最后一列列號
For Each Sht In Worksheets
If Sht.Name <> ToSht.Name Then '排除保存匯總結(jié)果的工作表
EndRow = Sht.Range("A1048576").End(xlUp).Row
EndCol = Sht.UsedRange.Columns.Count '最后一列列號
DataArr = Sht.Range(Sht.Cells(2, "A"), Sht.Cells(EndRow, EndRow)).Value
Set ToRng = ToSht.Range("A1048576").End(xlUp).Offset(1, 0)
ToRng.Resize(UBound(DataArr, 1), EndCol) = DataArr
End If
Next Sht
End Sub
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。