Computing.Net > Forums > Office Software > Delete named columns macro help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete named columns macro help

Reply to Message Icon

Name: Amnesiac
Date: April 16, 2009 at 16:33:12 Pacific
OS: Windows XP
Subcategory: Microsoft Office
Comment:

I need to write a macro in excel that will delete every column with the header name in the first row of "NAME ME." This is a task that will need to be completed many times and the columns to be deleted are not always the same. How would I do this and is it even possible?



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: April 16, 2009 at 19:26:27 Pacific
Reply:

Sub NoNameMe()
'Find last column with data in Row 1
 lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
  For delCol = lastCol To 1 Step -1
'Delete columns with Name Me in Row 1
   If Cells(1, delCol) = "Name Me" Then _
     Cells(1, delCol).EntireColumn.Delete
  Next
End Sub


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Delete named columns macro help

More macro help www.computing.net/answers/office/more-macro-help/6035.html

Excel: Macro Help www.computing.net/answers/office/excel-macro-help/7252.html

Need Help With Excel Macros www.computing.net/answers/office/need-help-with-excel-macros/8465.html