Delete named columns macro help

April 16, 2009 at 16:33:12
Specs: Windows XP
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?

See More: Delete named columns macro help

Report •

April 16, 2009 at 19:26:27
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
End Sub

Report •
Related Solutions

Ask Question