尝试从F列(F2:F)复制数据,然后粘贴到D列的第一个空行。
然后对G列(G2:G)执行相同操作,粘贴到E的第一个空行。
从H粘贴到(D的新第一个空行)的数据。
我粘贴的数据(E的新的第一个空行)....通过M列
需要遍历Workbook中的所有工作表并执行完全相同的操作。
问题:所有行上的“语法错误”:
ActiveSheet.Range(“F2:F” & copyLastrow).Copy Destination:=ActiveSheet.Range(“D” & pasteLastrowD)
他们都是红色的
我认为我的问题是我不知道Active.Sheet的命名约定
到目前为止代码:
Sub Doit()
Dim ws As Worksheet
For Each ws In Worksheets
copyLastrow = ActiveSheet.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
pasteLastrowD = ActiveSheet.Range(“D” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“F2:F” & copyLastrow).Copy Destination:=ActiveSheet.Range(“D” & pasteLastrowD)
pasteLastrowE = ActiveSheet.Range(“E” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“G2:G” & copyLastrow).Copy Destination:=ActiveSheet.Range(“E” & pasteLastrowE)
pasteLastrowD = ActiveSheet.Range(“D” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“H2:H” & copyLastrow).Copy Destination:=ActiveSheet.Range(“D” & pasteLastrowD)
pasteLastrowE = ActiveSheet.Range(“E” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“I2:I” & copyLastrow).Copy Destination:=ActiveSheet.Range(“E” & pasteLastrowE)
pasteLastrowD = ActiveSheet.Range(“D” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“J2:J” & copyLastrow).Copy Destination:=ActiveSheet.Range(“D” & pasteLastrowD)
pasteLastrowE = ActiveSheet.Range(“E” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“K2:K” & copyLastrow).Copy Destination:=ActiveSheet.Range(“E” & pasteLastrowE)
pasteLastrowD = ActiveSheet.Range(“D” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“L2:L” & copyLastrow).Copy Destination:=ActiveSheet.Range(“D” & pasteLastrowD)
pasteLastrowE = ActiveSheet.Range(“E” & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Range(“M2:M” & copyLastrow).Copy Destination:=ActiveSheet.Range(“E” & pasteLastrowE)
Next
End Sub
答案 0 :(得分:0)
上面的评论,刚刚修改了第一对夫妇,但希望你能得到这个想法。您需要完全引用所有范围/单元格引用。您还需要更改引号。
Sub Doit()
Dim ws As Worksheet
For Each ws In Worksheets
copyLastrow = ws.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
pasteLastrowD = ws.Range("D" & Rows.Count).End(xlUp).Row + 1
ws.Range("F2:F" & copyLastrow).Copy Destination:=ws.Range("D" & pasteLastrowD)
'etc
答案 1 :(得分:0)
Sub Doit()
Dim ws As Worksheet
For Each ws In Worksheets
With ws
For Each cell In .Range("F2:M2")
.Range(cell, .Cells(.Rows.Count, cell.Column).End(xlUp).Copy Destination:=.Cells(.Rows.Count, "D").End(xlUp).Offset(1, cell.Column Mod 2)
Next cell
End With
Next ws
End Sub