cycling through columns?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to know if it is possible to numerically cycle through the columns.
You can do this with cells, by using range (x,y) which allows you to
reference columns and rows numerically. I want to be able to reference the
column numerically so that I can set widths based on what column number I am
in.

I want to be able to do something like this

For x = 1 to totnumofcolumnsbeingused

if x = 5 or x = 9 then
set the width of the 5th or 9th column to 15
end if

next x

is this possible? Any help would be appreciated. Thanks.

Kirk
 
Dim i as Long
for i = 1 to 256
if i = 5 or i = 9 then
msgbox Columns(i).Address
end if
Next

You can also do

Dim i as long, col as Range
for i = 1 to 256
set col = cells(1,i).EntireColumn
if i = 5 or i = 6 then
msgbox col.Address
end if
Next
 
Tom,

Thanks that worked.

Kirk

Tom Ogilvy said:
Dim i as Long
for i = 1 to 256
if i = 5 or i = 9 then
msgbox Columns(i).Address
end if
Next

You can also do

Dim i as long, col as Range
for i = 1 to 256
set col = cells(1,i).EntireColumn
if i = 5 or i = 6 then
msgbox col.Address
end if
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top