Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Deleting Columns Based upon Heading
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Deleting Columns Based upon Heading
Hi Jessica,
Assume your headers are in row 1, try: : '============= Public Sub Tester() Dim Rng As Range Set Rng = Rows(1).Find(What:="Bidder", _ After:=Range("A1"), _ MatchCase:=False) If Not Rng Is Nothing Then Rng.EntireColumn.Delete End Sub '<<============= Change Rows(1) to accord with the header row. --- Regards, Norman "Jessica" wrote in message ... 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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Return Column Heading based on value in row | New Users to Excel | |||
formula to look up and sum the Grand totals based on the Heading | Excel Discussion (Misc queries) | |||
1 Heading for 2 columns | Excel Discussion (Misc queries) | |||
Deleting columns based upon the value that appears in column A | Excel Programming | |||
Deleting columns based upon the value that appears in ROW A | Excel Programming |