Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Delete columns

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Delete columns

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Delete columns

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Delete columns

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
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 columns if 0 jatman New Users to Excel 2 January 3rd 09 04:39 AM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM
I can't delete columns - help! dcleesfo Excel Worksheet Functions 3 September 16th 05 02:00 AM
Delete Columns Jean[_5_] Excel Programming 1 March 5th 04 02:03 PM
Delete columns Elsie Excel Programming 1 February 28th 04 03:08 AM


All times are GMT +1. The time now is 10:16 AM.

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"