Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return Column Heading based on value in row Lee New Users to Excel 2 May 21st 09 06:06 PM
formula to look up and sum the Grand totals based on the Heading Narnimar Excel Discussion (Misc queries) 4 March 16th 09 01:31 PM
1 Heading for 2 columns Beth Excel Discussion (Misc queries) 9 November 18th 07 01:44 PM
Deleting columns based upon the value that appears in column A Steve Excel Programming 3 September 23rd 04 02:42 PM
Deleting columns based upon the value that appears in ROW A Steve Excel Programming 4 September 23rd 04 02:29 PM


All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"