Hey there everyone,
First post on the forum, have been grabbing info here for awhile. Feel free to blow me up when I don't follow the SOP.
I am trying to create a macro that will delete all columns aside from those specified. They must be labeled by the actual column header as data imports can vary greatly. Columns I would like to keep, based on header name are: Word , Pay, Cost, Volume, Rank, & Type
I really have searched the forum high and low also all over google. Everything is detailed on deleting rows or deleting columns by specifying header to be deleted (not what I want to achieve).
Thank you.
Last edited by macattackr; 01-27-2012 at 09:33 AM.
Hi macattackr and welcome to the forum.
Try this code in the attached sample file.
Note - LastCol looks in Row 1 for your column headers.Sub DelColumnNotInList() Dim LastCol As Double Dim ColCtr As Double LastCol = Cells(1, Columns.Count).End(xlToLeft).Column For ColCtr = 1 To LastCol If InStr("Word Pay Cost Volume Rank Type", Cells(1, ColCtr).Text) = 0 Then Cells(1, ColCtr).EntireColumn.Delete ColCtr = ColCtr - 1 End If Next ColCtr End Sub
One test is worth a thousand opinions.
Click the * below to say thanks.
Hey Marvin that worked great....thank you...i will be submitting another question shortly! starting to learn and pick it up
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks