Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. I'm looking for a way to delete a series of columns, starting in column
"B". I want to search for the word, "Total" in row 1. I want to delete all columns up to the column with the word "Total in it. For instance, If J1 contains "Total", I would want to delete columns B through I. Thanks, Mike. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try This
Sub DeleteColumns() LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column Set HeaderRange = Range(Cells(1, 2), Cells(1, LastColumn)) Set c = HeaderRange.Find("Total", LookIn:=xlValues) If Not c Is Nothing Then Set DeleteRange = Range(Cells(1, 2), _ Cells(1, c.Column - 1)) DeleteRange.EntireColumn.Delete End If End Sub "Mike D." wrote: Hi. I'm looking for a way to delete a series of columns, starting in column "B". I want to search for the word, "Total" in row 1. I want to delete all columns up to the column with the word "Total in it. For instance, If J1 contains "Total", I would want to delete columns B through I. Thanks, Mike. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
With the addition of this line ............
Dim LastColumn As Long below Sub DeleteColumns() Gord Dibben MS Excel MVP On Sat, 5 May 2007 13:34:00 -0700, Joel wrote: Try This Sub DeleteColumns() LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column Set HeaderRange = Range(Cells(1, 2), Cells(1, LastColumn)) Set c = HeaderRange.Find("Total", LookIn:=xlValues) If Not c Is Nothing Then Set DeleteRange = Range(Cells(1, 2), _ Cells(1, c.Column - 1)) DeleteRange.EntireColumn.Delete End If End Sub "Mike D." wrote: Hi. I'm looking for a way to delete a series of columns, starting in column "B". I want to search for the word, "Total" in row 1. I want to delete all columns up to the column with the word "Total in it. For instance, If J1 contains "Total", I would want to delete columns B through I. Thanks, Mike. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Joel!
"Joel" wrote: Try This Sub DeleteColumns() LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column Set HeaderRange = Range(Cells(1, 2), Cells(1, LastColumn)) Set c = HeaderRange.Find("Total", LookIn:=xlValues) If Not c Is Nothing Then Set DeleteRange = Range(Cells(1, 2), _ Cells(1, c.Column - 1)) DeleteRange.EntireColumn.Delete End If End Sub "Mike D." wrote: Hi. I'm looking for a way to delete a series of columns, starting in column "B". I want to search for the word, "Total" in row 1. I want to delete all columns up to the column with the word "Total in it. For instance, If J1 contains "Total", I would want to delete columns B through I. Thanks, Mike. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
delete columns if 0 | New Users to Excel | |||
merge text from 2 columns into 1 then delete the old 2 columns | Excel Worksheet Functions | |||
I can't delete columns - help! | Excel Worksheet Functions | |||
Delete Columns | Excel Programming | |||
Delete columns | Excel Programming |