Public Sub huizong() ''许格式相同表格汇总同工作表
Dim r As Long, c As Long
r = 1
c = 8
Range(Cells(r + 1, "A"), Cells(65536, c)).ClearContents
Application.ScreenUpdating = False
Dim FileName As String, wb As Workbook, sht As Worksheet, erow As Long
Dim fn As String, arr As Variant
FileName = Dir(ThisWorkbook.path & "\*.xls")
Do While FileName <> ""
If FileName <> ThisWorkbook.Name Then
erow = Range("A1").CurrentRegion.Rows.Count + 1
fn = ThisWorkbook.path & "\" & FileName
Set wb = GetObject(fn)
Set sht = wb.Worksheets(1)
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(65536, "B").End(xlUp).Offset(0, 8))
Cells(erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
wb.Close False
End If
FileName = Dir
Loop
Application.ScreenUpdating = True
End Sub 收起
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(65536, "B").End(xlUp).Offset(0, 8))
Cells(erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
Resize(UBound(arr, 1), UBound(arr, 2) 这句什么意思
追答resize()是一个扩展单元格地址区域的函数,有两个参数,第一个是行扩展数,第二个是列扩展数
UBound() 是获取数组最大索引数,也有两参数,第一个是数组名,第二个是数组的维,
这里是把数组的 第一维的最大索引 充当了 RESIZE 的行扩展,第二维的最大索引数 充当了 resize的列扩展数,