PC Review


Reply
Thread Tools Rate Thread

Delete multiple columns based on certain criteria

 
 
=?Utf-8?B?R3JldHRh?=
Guest
Posts: n/a
 
      22nd Mar 2007
I need to delete several non-adjacent columns. I would like to delete based
upon the column name, which will always be in the first row, but the columns
are not necessarily in the same order.

How can I best automate this?

TIA

Gretta
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      22nd Mar 2007
Gretta,

Change the value of the myFindString from this:

myFindString = "Delete me"

to the name that needs deleting, and run the macro below.

HTH,
Bernie
MS Excel MVP

Sub DeleteColumns()
Dim c As Range ' The cell found with what you want
Dim d As Range ' All the cells found with what you want
Dim myFindString As String
Dim firstAddress As String

myFindString = "Delete me"

'Find all the cells with the delete phrase
With Range("1:1")

Set c = .Find(myFindString, LookIn:=xlValues, lookAt:=xlWhole)

If Not c Is Nothing Then
Set d = c
firstAddress = c.Address
Else:
MsgBox "Not Found"
End
End If

Set c = .FindNext(c)
If Not c Is Nothing And c.Address <> firstAddress Then
Do
Set d = Union(d, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

'Now delete those columns
d.EntireColumn.Delete

End Sub



"Gretta" <(E-Mail Removed)> wrote in message
news:4104300F-1D57-4380-906F-(E-Mail Removed)...
>I need to delete several non-adjacent columns. I would like to delete based
> upon the column name, which will always be in the first row, but the columns
> are not necessarily in the same order.
>
> How can I best automate this?
>
> TIA
>
> Gretta



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows based on multiple criteria puiuluipui Microsoft Excel Misc 6 3rd Jul 2009 01:58 PM
how can I have a formula result based on multiple criteria/columns =?Utf-8?B?bmlja3lfcA==?= Microsoft Excel New Users 1 5th Jul 2006 01:45 PM
Help w/ counting multiple columns based on IF criteria =?Utf-8?B?Q29uc3RydWN0aW9uR3V5?= Microsoft Excel Worksheet Functions 3 8th Nov 2005 04:03 AM
Return value based on certain criteria in multiple columns kilaalaa Microsoft Excel Programming 0 3rd Nov 2005 03:51 PM
SUMIF in multiple columns based on other criteria in Excel? =?Utf-8?B?U2NvdHQgUG93ZWxs?= Microsoft Excel Misc 9 13th Apr 2005 02:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:07 AM.