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

Excel 2003

Hello.
I have this code from a macro and am looking to streamline it:

<begin macro
Columns("A:A").Select
Selection.NumberFormat = "General"

Columns("B:B").Select
Selection.NumberFormat = "General"

Columns("C:C").Select
Selection.NumberFormat = "General"

Columns("D:D").Select
Selection.NumberFormat = "@"

Columns("E:E").Select
Selection.NumberFormat = "@"

Columns("F:F").Select
Selection.NumberFormat = "General"

Columns("G:G").Select
Selection.NumberFormat = "@"

Columns("H:H").Select
Columns("I:I").Select
Selection.NumberFormat = "@"

Columns("J:J").Select
Selection.NumberFormat = "0"

Columns("K:K").Select
Selection.NumberFormat = "0"
<end macro

I am not sure how to set up code to loop through an .XLS file to get the
sheetname, count the valid columns and rows (column/row numbers can
change from month to month)
Then as I loop through each column if it is A,B,C, or F then set
numberformat to "General", etc.....

Do I have to invoke the Excel Object -and- the Workbook object, -and-
the sheet object? This is where I get confused.

Thnx....


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Looping through columns

I'm not sure I understand what you're doing, but if you wanted to loop through
all the worksheets in the activeworkbook, you could do something like:

Dim Wks as worksheet
for each wks in activeworkbook.worksheets
with wks
.range("a1:c1,f1").entirecolumn.numberformat = "General"
.Range("d1:E1,g1,i1,j1,k1").entirecolumn.numberfor mat = "@"
.range("j1:k1").entirecolumn.numberformat = "0"
end with
next wks

I was confused about what happens with column H, though.

RLN wrote:

Excel 2003

Hello.
I have this code from a macro and am looking to streamline it:

<begin macro
Columns("A:A").Select
Selection.NumberFormat = "General"

Columns("B:B").Select
Selection.NumberFormat = "General"

Columns("C:C").Select
Selection.NumberFormat = "General"

Columns("D:D").Select
Selection.NumberFormat = "@"

Columns("E:E").Select
Selection.NumberFormat = "@"

Columns("F:F").Select
Selection.NumberFormat = "General"

Columns("G:G").Select
Selection.NumberFormat = "@"

Columns("H:H").Select
Columns("I:I").Select
Selection.NumberFormat = "@"

Columns("J:J").Select
Selection.NumberFormat = "0"

Columns("K:K").Select
Selection.NumberFormat = "0"
<end macro

I am not sure how to set up code to loop through an .XLS file to get the
sheetname, count the valid columns and rows (column/row numbers can
change from month to month)
Then as I loop through each column if it is A,B,C, or F then set
numberformat to "General", etc.....

Do I have to invoke the Excel Object -and- the Workbook object, -and-
the sheet object? This is where I get confused.

Thnx....

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Looping through columns


Your solution worked great, Dave, thank you! I appreciate your help
very much.

RLN


*** Sent via Developersdex http://www.developersdex.com ***
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
Looping through columns Mick[_2_] Excel Programming 1 February 7th 08 07:27 PM
looping across columns in range? Amy Excel Discussion (Misc queries) 3 July 19th 05 08:01 PM
Looping thru columns Robert Excel Programming 5 June 15th 05 09:48 AM
Looping through columns teresa Excel Programming 2 December 31st 04 07:25 PM
Looping thru columns beyond Z John Pierce Excel Programming 3 January 23rd 04 12:17 AM


All times are GMT +1. The time now is 09:11 AM.

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"