Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete and re-arrange cols


I have data, 20 columns and approx 600 rows.
In the 1st row are column Headings.
I need to write a macro so that if a Column Heading isn't one of:
Cbt1,Cbt3,Cbt4,Cbt5,Cbt7,Account,Amount
Then the column is deleted.
The remaining columns are then re-arranged in the order:
Cbt4,Amount,Account,Cbt1,Cbt5,Cbt3,Cbt7.

Below is my effort to date, not quite working, thks

Sub CB()

lastcol = Range("IV1").End(xlToLeft).Column
MsgBox lastcol

For i = 1 To lastcol

If Cells(1, i) < "Cbt1" And Cells(1, i) < "Cbt3" And Cells(1, i) <
"Cbt4" And Cells(1, i) < "Cbt5" And Cells(1, i) < "Cbt7" And Cells(1
i) < "Account" And Cells(1, i) < "Amount" Then
Cells(1, i).EntireColumn.Delete
End If
Next
End Su

--
T De Villier
-----------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...fo&userid=2647
View this thread: http://www.excelforum.com/showthread.php?threadid=56421

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete and re-arrange cols

Start from the right and work toward the left:

For i = lastcol To 1 Step -1



T De Villiers wrote:

I have data, 20 columns and approx 600 rows.
In the 1st row are column Headings.
I need to write a macro so that if a Column Heading isn't one of:
Cbt1,Cbt3,Cbt4,Cbt5,Cbt7,Account,Amount
Then the column is deleted.
The remaining columns are then re-arranged in the order:
Cbt4,Amount,Account,Cbt1,Cbt5,Cbt3,Cbt7.

Below is my effort to date, not quite working, thks

Sub CB()

lastcol = Range("IV1").End(xlToLeft).Column
MsgBox lastcol

For i = 1 To lastcol

If Cells(1, i) < "Cbt1" And Cells(1, i) < "Cbt3" And Cells(1, i) <
"Cbt4" And Cells(1, i) < "Cbt5" And Cells(1, i) < "Cbt7" And Cells(1,
i) < "Account" And Cells(1, i) < "Amount" Then
Cells(1, i).EntireColumn.Delete
End If
Next
End Sub

--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=564217


--

Dave Peterson
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
Macro To Delete/Add & Rename/Arrange Sheets steven.holloway Excel Discussion (Misc queries) 5 June 13th 08 06:40 PM
Arrange column after delete Gil[_4_] Excel Programming 2 May 7th 06 12:01 AM
Range.Select 1st pass 13 cols, 2nd paqss 25 cols twice as wide in error? Craigm[_53_] Excel Programming 2 May 2nd 06 11:04 AM
Cond Format:re color 2 cols, skip 2 cols Tat Excel Worksheet Functions 2 June 22nd 05 06:43 PM
Import csv files, delete rows, arrange columns .... xadnora Excel Programming 8 April 11th 05 04:48 PM


All times are GMT +1. The time now is 05:41 PM.

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

About Us

"It's about Microsoft Excel"