尝试执行下面的代码时,我显示语法错误
Sub collate3()
Dim wb As Workbook
Dim sh As Worksheet
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim lr As Long
Dim shAry
Range("A6:AZ7000").ClearContents
For i = 2 To 3
Set sh1 = Workbooks(i).Sheets("DNY") 'Edit sheet name
shAry = Array(sh1)
For j = LBound(shAry) To UBound(shAry)
Set sh = ThisWorkbook.Sheets(j + 1)
lr = shAry(j).UsedRange.Rows.Count
shAry(j).Range("L5:S" & lr).EntireRow.Copy _
sh.Cells(Rows.Count, 1).End(xlUp)(6).PasteSpecial xlPasteValues
Next
Next
Range("A:A,C:K,Q:R,T:Z").Delete
End Sub
当我加入sh.Cells(Rows.Count, 1).End(xlUp)(6).PasteSpecial xlPasteValues
时会发生错误。
如果我做sh.Cells(Rows.Count, 1).End(xlUp)(6)
它可以正常工作但是我只需要值
答案 0 :(得分:1)
如果你只是想让它编译,你需要在你的.PasteSpecial参数周围添加()。像这样:
shAry(j).Range("L5:S" & lr).EntireRow.Copy _
sh.Cells(Rows.Count, 1).End(xlUp)(6).PasteSpecial(xlPasteValues)
但是,我认为这不是你想要实现的目标。 Range.Copy方法期望 Destination 参数作为其参数,而不是PasteSpecial Action 。
(6)的目的是什么?