The range to be copied here ActiveSheet.Range("F2:K").Copy
is not completely defined. There is a row for the K
column missing.
Gessing that busdates
is inteded to be a range, then it should be assigned as such:
Dim busDates As Range
Set busDates = Sheets("stack").Range("M3:M" & lastRow - 1)
And looping through the rows of a range is a bit meaningless, if the d
variable is not used in the loop, but still:
For d = 2 To busDates.Rows.Count + 2
ActiveSheet.Range("F2:K" & lastRow).Copy
ActiveSheet.Range("M" & lastRow).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next
Probably looping through busDates
could be done like this:
Dim myCell As Range
For Each myCell In busDates
If myCell.Row > 2 Then
'some cut and copy here
End If
Next myCell
Last but not least, the ActiveSheet
is to be avoided in VBA, but in this case it is probably harmless - How to avoid using Select in Excel VBA.
The whole code that works somehow is here:
Sub TestMe()
Dim lastRow As Long
lastRow = WorksheetFunction.Max(Sheets("stack").Cells(Rows.Count, "M").End(xlUp).Row)
lastRow = lastRow + 1
Dim busDates As Range
Set busDates = Sheets("stack").Range("M3:M" & lastRow - 1)
Dim d As Long
For d = 2 To busDates.Rows.Count + 2
ActiveSheet.Range("F2:K" & lastRow).Copy
ActiveSheet.Range("M" & lastRow).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next
End Sub