View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default Deleting Columns Based upon Heading

Give this a whirl...

Sub Test()
DeleteColumns "Bidder"
DeleteColumns "That"
End Sub

Sub DeleteColumns(ByVal strHeader As String)
Dim rngFound As Range
Dim wks As Worksheet

Set wks = ActiveSheet

Set rngFound = wks.Rows(1).Find(strHeader)

If rngFound Is Nothing Then
MsgBox strHeader & " was not found."
Else
rngFound.EntireColumn.Delete
End If

End Sub
--
HTH...

Jim Thomlinson


"Jessica" wrote:

I am writing a macro where I need to delete certain columns. I can write the
code to delete columns by the letter (i.e., if I want to delete column C).
However I want to delete a column based upon the heading.

For instance, I want to delete the column entitled "Bidder". I can write a
macro to find the header "Bidder", but I am not sure how to indicate that I
want the column that the active cell is in to be deleted.