- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 4# morris0914 - Sub Compare()
- Dim R As Integer, C As Integer, TheCoL As Integer
- On Error GoTo Er
- With ActiveWorkbook
- .Sheets.Add(, .Sheets(.Sheets.Count)).Name = "合併"
- End With
- With Sheets("合併")
- .Move Sheets(2)
- Sheets(3).Range("A1").CurrentRegion.Copy .[A1]
- R = .[A1].End(xlDown).Row + 2
- For C = 1 To Sheets(3).UsedRange.Columns.Count
- 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
- With Sheets(i)
- .Range(.Cells(R, C), .Cells(.Rows.Count, C)).Copy Sheets("合併").Cells(R, TheCoL)
- End With
- Next
- Next
- End With
- Exit Sub
- Er: '處裡 "合併" 工作表已存在
- Application.DisplayAlerts = False
- ActiveSheet.Delete
- Sheets("合併").Delete
- Application.DisplayAlerts = True
- Resume
- End Sub
複製代碼 |
|