Sub Compare()
Dim Sh As Worksheet, i%, iRowEnd%, Ar()
With ActiveWorkbook
.Sheets.Add(, .Sheets(.Sheets.Count)).Name = "合併"
End With
With Sheets("合併")
.Move Sheets(2)
.UsedRange.Offset(1).ClearContents
For i = 2 To Sheets.Count
iRowEnd = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
Ar = Sheets(i).Range("A2:BB" & iRowEnd).Value '<========BB
.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(UBound(Ar), 50) = Ar '<====50
Next
End With
End Sub作者: stillfish00 時間: 2013-5-31 19:47
Sub Compare()
Dim Sh As Worksheet, i%, iRowEnd%, iColEnd%, Ar()
With ActiveWorkbook
.Sheets.Add(, .Sheets(.Sheets.Count)).Name = "合併"
End With
With Sheets("合併")
.Move Sheets(2)
.UsedRange.Offset(1).ClearContents
For i = 2 To Sheets.Count
iRowEnd = Sheets(i).Cells(Rows.Count, 1).End(xlUp).Row
iColEnd = Sheets(i).Cells(1, Columns.Count).End(xlToLeft).Column
Ar = Sheets(i).Range("A2:" & .Cells(iRowEnd, iColEnd).Address).Value
.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(UBound(Ar), UBound(Ar, 2)) = Ar
Next
End With
End Sub作者: morris0914 時間: 2013-6-3 10:39
For C = 1 To Sheets(3).UsedRange.Columns.Count '我的頁面是(menu, 合併, 4.log, 5.log)為何是1 To Sheets(3),而不是Sheets(3) to.....
For i = 3 To Sheets.Count
TheCoL = .Cells(R, .Columns.Count).End(xlToLeft).Column + 1
If .Cells(R, .Columns.Count).End(xlToLeft) = "" Then TheCoL = 1 ' 為何讀到xlToLeft為空白時,TheCol=1,而不是用xlToright
With Sheets(i)
.Range(.Cells(R, C), .Cells(.Rows.Count, C)).Copy Sheets("合併").Cells(R, TheCoL) '為何用到2次Cells
End With
Next
Next作者: morris0914 時間: 2013-6-4 18:26