Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 20
Default excel columns collection?

Just checking if there is such a collection in excel as a
columns collection. I want to loop through a columns
collection for formatting.

Pseudocode

Dim col As Column, cols As Columns
Set cols = Columns(A:J)
For each col in cols
col.width = 10
Next

Is there a way to do something like this?

Thanks,
Ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default excel columns collection?

There's a range object you can use:

dim Col as range
dim cols as range

set cols = range("a:j")
'I like that better than columns("a:j"), but it won't matter.

for each col in cols.columns
col.columnwidth = 10
next col

but why not just:

columns("a:j").columnwidth = 10

===
I changed it to .columnwidth, too.


Ron wrote:

Just checking if there is such a collection in excel as a
columns collection. I want to loop through a columns
collection for formatting.

Pseudocode

Dim col As Column, cols As Columns
Set cols = Columns(A:J)
For each col in cols
col.width = 10
Next

Is there a way to do something like this?

Thanks,
Ron


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
ron ron is offline
external usenet poster
 
Posts: 20
Default excel columns collection?

I think I figured this out

Dim sht As WorkSheet, i As Integer, col As Variant
Set sht = Sheets("Sheet1")
For i = 1 to sht.Columns("A:J").Count
sht.Columns(i).ColumnWidth = 11.5
Next

'--or

For each col in Sht.Columns("A:J")
Debug.print col.ColumnWidth
Next

-----Original Message-----
Just checking if there is such a collection in excel as a
columns collection. I want to loop through a columns
collection for formatting.

Pseudocode

Dim col As Column, cols As Columns
Set cols = Columns(A:J)
For each col in cols
col.width = 10
Next

Is there a way to do something like this?

Thanks,
Ron
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default excel columns collection?

Ron,

This may be more specific than you want, but it works for the situation you
describe:

Range("A1:J1").ColumnWidth = 2

More generally, no, there is no columns collection. Instead define ranges
and then use the .column or .entirecolumn or similar properties of those
ranges, e.g.,:

Sub test()
Dim col As Range
For Each col In Range("A1:J1")
col.ColumnWidth = 2
Next
End Sub

hth,

Doug

"Ron" wrote in message
...
Just checking if there is such a collection in excel as a
columns collection. I want to loop through a columns
collection for formatting.

Pseudocode

Dim col As Column, cols As Columns
Set cols = Columns(A:J)
For each col in cols
col.width = 10
Next

Is there a way to do something like this?

Thanks,
Ron



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
A link to a collection of videos and tutorials on MS excel:Add-in. datakid .. Excel Discussion (Misc queries) 0 March 25th 10 06:50 PM
Excel data collection Bill Needham Excel Discussion (Misc queries) 2 January 11th 08 06:02 PM
Excel 2003 macro collection bluepuppet Excel Discussion (Misc queries) 3 January 17th 07 10:55 PM
how do i create a data collection form in excel? stacy New Users to Excel 1 October 26th 05 08:21 PM
Keybindings Collection in Excel John[_88_] Excel Programming 1 July 26th 04 06:03 PM


All times are GMT +1. The time now is 09:02 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"