I have a macro that takes an input and finds a sheet with a matching name. From there it loops through the first row (headers) to find the column that matches a second input.
I want to copy that entire column and paste it onto a different sheet.
When I run the code, it works until the copy/ paste where I get
"Run-time error '1004' Application-defined or object-defined error
noted with a comment.
SDay = Sheets("Heat Map").Range("C1").Value
STime = Sheets("Heat Map").Range("C2").Value
Worksheets(SDay).Activate
For i = 2 To 17
If ActiveSheet.Cells(1, i).Value = Sheets("Heat Map").Range("C2").Value Then
ActiveSheet.Range(Cells(2, i), Cells(19, i)).Select ' Error is here
Selection.Copy
End If
Next i
Sheets("Heat Map").Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Heat Map").Activate