我正在尝试使用以下代码将一些数据复制到不同的工作表:
Sub FilterButton()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'fill in the Source Sheet and range
Set SourceRange = Sheets("Imported Data").Range("A1:K1")
'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("Test")
Lr = lastRow(DestSheet)
'With the information from the LastRow function we can
'create a destination cell
Set DestRange = DestSheet.Range("A" & Lr + 1)
'Copy the source range and use PasteSpecial to paste in
'the destination cell
SourceRange.Copy
DestRange.PasteSpecial _
Paste:=xlPasteValues, _
operation:=xlPasteSpecialOperationNone, _
skipblanks:=False, _
Transpose:=False
Application.CutCopyMode = False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
只有当我尝试这样做时,我才会收到以下错误:编译错误:未定义子或函数(此错误指向 lastRow)......我该如何解决这个问题?
编辑:
Sub FilterButton()
Dim SourceRange As Range, SRange, DestRange, myMultipleRange As Range
Dim DestSheet As Worksheet, Lr As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'fill in the Source Sheets and ranges
Set SourceRange = Sheets("Imported Data").Range("A2:B:C")
Set SRange = Sheets("Imported Data").Range("E2:E8")
Set myMultipleRange = Union(SourceRange, SRange)
'Fill in the destination sheet and find the last known cell
Set DestSheet = Sheets("Test")
'With the information on the new sheet
Set DestRange = DestSheet.Range("A:B:C:E")
'Copy the source range and use PasteSpecial to paste in
'the destination cell
myMultipleRange.Copy
DestRange.PasteSpecial _
Paste:=xlPasteValues, _
operation:=xlPasteSpecialOperationNone, _
skipblanks:=False, _
Transpose:=False
Application.CutCopyMode = False
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
我想要这些范围,但我不能在多项选择中使用范围:(!