按顺序将多张工作表中的行复制到另一张工作表
Copy rows from multiple sheets to another sequentially
我正在尝试编写一个脚本来获取所有行(在 header 行之后),然后将它们按顺序复制到第一个选项卡中。我也有 10 个选项卡,我希望它这样做,然后将它们依次粘贴到第一个选项卡中(基本上从其他 sheet 中拉出所有内容,然后像大一样将其放入第一个 sheet master sheet or report)
我试过了,但没用
Sub Report()
page = 2
row = 1
Dim lastRow As Integer
Dim pae As Integer
Dim rw As Integer
Dim WSheet(1 To 12) As Worksheet
lastRow = Worksheets(page).Cells(Rows.Count, "A").End(xlUp).rw
While (pge <= 12)
While (rw <= lastRow)
rw = rw + 1
ws1.Rows(row).EntireRow.Copy WSheet(pge).Range("A" & lastRow)
Wend
pge = pge + 1
Wend
End Sub
我试图让它计算有多少行有数据,然后将所有这些行复制到第一个 sheet,然后再转到下一个 sheet、
似乎跳过了我声明变量的地方,然后在最后一行赋值时出错
如有任何帮助,我们将不胜感激
请尝试下一个代码:
Sub ReportMaster()
Dim ws1 As Worksheet, ws As Worksheet, lastRow As Long, lastER As Long, lastCol As Long
Set ws1 = Worksheets(1)
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ws1.Name Then
lastRow = ws.Range("A" & ws.rows.count).End(xlUp).row
lastCol = ws.cells(1, ws.Columns.count).End(xlToLeft).Column
lastER = ws1.Range("A" & ws.rows.count).End(xlUp).row + 1 'last empty row
ws.Range(ws.Range("B1"), ws.cells(lastRow, lastCol)).Copy ws1.Range("A" & lastER)
End If
Next ws
End Sub
我正在尝试编写一个脚本来获取所有行(在 header 行之后),然后将它们按顺序复制到第一个选项卡中。我也有 10 个选项卡,我希望它这样做,然后将它们依次粘贴到第一个选项卡中(基本上从其他 sheet 中拉出所有内容,然后像大一样将其放入第一个 sheet master sheet or report)
我试过了,但没用
Sub Report()
page = 2
row = 1
Dim lastRow As Integer
Dim pae As Integer
Dim rw As Integer
Dim WSheet(1 To 12) As Worksheet
lastRow = Worksheets(page).Cells(Rows.Count, "A").End(xlUp).rw
While (pge <= 12)
While (rw <= lastRow)
rw = rw + 1
ws1.Rows(row).EntireRow.Copy WSheet(pge).Range("A" & lastRow)
Wend
pge = pge + 1
Wend
End Sub
我试图让它计算有多少行有数据,然后将所有这些行复制到第一个 sheet,然后再转到下一个 sheet、
似乎跳过了我声明变量的地方,然后在最后一行赋值时出错
如有任何帮助,我们将不胜感激
请尝试下一个代码:
Sub ReportMaster()
Dim ws1 As Worksheet, ws As Worksheet, lastRow As Long, lastER As Long, lastCol As Long
Set ws1 = Worksheets(1)
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ws1.Name Then
lastRow = ws.Range("A" & ws.rows.count).End(xlUp).row
lastCol = ws.cells(1, ws.Columns.count).End(xlToLeft).Column
lastER = ws1.Range("A" & ws.rows.count).End(xlUp).row + 1 'last empty row
ws.Range(ws.Range("B1"), ws.cells(lastRow, lastCol)).Copy ws1.Range("A" & lastER)
End If
Next ws
End Sub