Sub CombineSheet()
Dim i, j, k, n As Integer
n = 1
For i = 2 To ThisWorkbook.Sheets.Count
For j = 1 To ThisWorkbook.Sheets(i).UsedRange.Rows.Count
For k = 1 To ThisWorkbook.Sheets(i).UsedRange.Columns.Count
ThisWorkbook.Sheets(1).Cells(n, k).Value = ThisWorkbook.Sheets(i).Cells(j, k).Value
Next k
n = n + 1
Next j
Next i
End Sub作者: stillfish00 時間: 2014-11-19 15:07
回復 1#s13983037
1. Integer 範圍 -32,768 到 32,767 ,
Long 範圍 -2,147,483,648 到 2,147,483,647
所以改Long就可以了
2. Dim i, j, k, n As Integer 要注意這樣的寫法只有n是宣告為 Integer,i、j、k都是宣告為variant。
如果都要宣告Long,要寫成這樣...
Dim i As Long, j As Long, k As Long, n As Long作者: s13983037 時間: 2014-11-19 18:12
大大您好 以下是我的VBA 程式碼 另有附件一為圖檔
Dim i As Long, j As Long, k As Long, n As Long
n = 1
For i = 2 To ThisWorkbook.Sheets.Count
For j = 1 To ThisWorkbook.Sheets(i).UsedRange.Rows.Count
For k = 1 To ThisWorkbook.Sheets(i).UsedRange.Columns.Count
ThisWorkbook.Sheets(1).Cells(n, k).Value = ThisWorkbook.Sheets(i).Cells(j, k).Value
Next k
n = n + 1
Next j
Next i