次のコードを使用して、一部のデータを別のシートにコピーしようとしています。
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
これを実行しようとすると、次のエラーが発生します: コンパイル エラー: Sub または Function が定義されていません (このエラーは 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
これらの範囲が必要ですが、複数の選択で範囲を使用することはできません:(!