Ritu Mishra
Ritu Mishra

Reputation: 83

Insert a new column before a certain column based on row header-VBA

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

Answers (1)

G42
G42

Reputation: 10019

In the time it took to confirm a solution, this seems to be answered in the comments.

Upvotes: 1

Related Questions