要解決本例中的問(wèn)題,可以將過(guò)程改寫為:
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ū)域的最后一列列號(hào)
For Each Sht In Worksheets
If Sht.Name <> ToSht.Name Then '排除保存匯總結(jié)果的工作表
EndRow = Sht.Range("A1048576").End(xlUp).Row
EndCol = Sht.UsedRange.Columns.Count '最后一列列號(hào)
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)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。