What I’m trying to do is scan over every header on one sheet (the headers are located in “1:1”), find a header called “Dealer Code”, then copy that entire column to another sheet.
My current problem is that there are blanks in the Dealer Code column so the selection stops. I would work from the bottom of the sheet upward to avoid this, but since the header cell is stored in an address, I can’t extract the column letter.
There a way I can include blanks in my selection, or extract the column letter and work upwards?
If I’m approaching the problem very inconveniently, please let me know! I want to learn as much as possible.
Below is my code. Help would be greatly appreciated.
'Copies over Dealer Codes
With Sheets("Raw Data").Range("1:1")
Set c = .Find("Dealer Code", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
Sheets("Raw Data").Range(firstAddress).Select
Sheets("Raw Data").Range(Selection, Selection.End(xlDown)).Select
Selection.Copy (Sheets("Copied Data").Range("A1"))
End With
Try something like this:
This selects the whole column, but is easily changed to select the elements from the 2nd row down to the end. Since you have blanks, something like
Range(column & "2:" & column & Range(column & "65536").End(xlUp).Row).Selectworks, but is a bit kludgey, I’ll admit.Other solutions may be more optimal.