Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Delete rows based on multiple criteria | Excel Discussion (Misc queries) | |||
Delete Formula Based on Multiple Columns | Excel Discussion (Misc queries) | |||
VBA Delete row based on multiple columns of data | Excel Discussion (Misc queries) | |||
Help w/ counting multiple columns based on IF criteria | Excel Worksheet Functions | |||
Return value based on certain criteria in multiple columns | Excel Programming |