Reputation: 83
I am simply trying to search for a specific column based on the header and insert a new column right before it (so to the left of the column). Right now my code searches for all columns that even contain my search and inserts a new column 2 columns to the left. For example I want to search for the header that says Paid to Date
ONLY but it even inserts a column next to Commission Paid to Date
etc.
Sheets(NewSheet).Select
Set ColHeaders = Range("A4:CD4").Find("Paid to Date")
If ColHeaders Is Nothing Then
MsgBox "Paid to Date Column was not found."
Exit Sub
Else
Columns(ColHeaders.Column).Offset(0, -1).Insert
End If
Upvotes: 1
Views: 2688
Reputation: 10019
In the time it took to confirm a solution, this seems to be answered in the comments.
Find
here and specify the argument LookAt
to be xlWhole
(put a value of 1, as per enumeration)Upvotes: 1