You need to qualify every Range, Rows, Columns, etc with a worksheet:
FrstEmtCll = Worksheets("Data").Range("A" & Worksheets("Data").Rows.Count).End(xlUp).Row
The second issue is that you declare Dim FrstEmptCll As Range
but you try to put the row number into a range object .End(xlUp).Row
.
So either Set
the range to the cell and offset:
Option Explicit
Sub Entry_Schedule()
' Entry_Schedule Macro
Dim FrstEmtCll As Range
Set FrstEmtCll = Worksheets("Data").Range("A" & Worksheets("Data").Rows.Count).End(xlUp).Offset(RowOffset:=1)
Worksheets("Sheet2").Range("D4:I4").Copy
FrstEmtCll.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Or use the row number (as Long
):
Option Explicit
Sub Entry_Schedule()
' Entry_Schedule Macro
Dim FrstEmptRow As Long
FrstEmptRow = Worksheets("Data").Range("A" & Worksheets("Data").Rows.Count).End(xlUp).Row + 1
Worksheets("Sheet2").Range("D4:I4").Copy
Worksheets("Data").Range("A" & FrstEmptRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Additionally you mistyped your variable name FrstEmptCll
vs FrstEmtCll
(missing p
). This means you actually have 2 different variables now (which easily blows up your code). To avoid such errors I highly recommend to activate Option Explicit
: In the VBA editor go to Tools › Options › Require Variable Declaration.
Range("A" & Rows.Count).End(xlUp).Row
isn't qualified with a worksheet. You did good and qualified the next two range objects with sheetsSheet2
andData
, but didn't qualify the range you are having issues with.