Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Delete multiple columns based on certain criteria

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Delete multiple columns based on certain criteria

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" wrote in message
...
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
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
Delete rows based on multiple criteria puiuluipui Excel Discussion (Misc queries) 6 July 3rd 09 01:58 PM
Delete Formula Based on Multiple Columns Cue Excel Discussion (Misc queries) 2 June 23rd 08 03:41 AM
VBA Delete row based on multiple columns of data jlclyde Excel Discussion (Misc queries) 3 November 26th 07 07:46 PM
Help w/ counting multiple columns based on IF criteria ConstructionGuy Excel Worksheet Functions 3 November 8th 05 04:03 AM
Return value based on certain criteria in multiple columns kilaalaa Excel Programming 0 November 3rd 05 03:51 PM


All times are GMT +1. The time now is 12:33 PM.

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

About Us

"It's about Microsoft Excel"