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

Hello.

I need some guidance here. I want to dimension a variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Iterate columns

Wired

one way:

Sub IterateThroughRange()
Dim Cell As Range
For Each Cell In ActiveSheet.UsedRange
Debug.Print Cell.Address
Next 'Cell
End Sub

Regards

Trevor


"wired" wrote in message
...
Hello.

I need some guidance here. I want to dimension a variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Iterate columns

Dim cell as Range
for each cell in Activesheet.UsedRange
' debug.print cell.address
Next

--
Regards,
Tom Ogilvy

"wired" wrote in message
...
Hello.

I need some guidance here. I want to dimension a variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Iterate columns

Try something like

Dim Rng As Range
For Each Rng In Worksheets("Sheet1").UsedRange
Debug.Print Rng.Address
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"wired" wrote in message
...
Hello.

I need some guidance here. I want to dimension a variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Iterate columns

I'm not sure why you would want to use a column as the base unit, but try
something like this:

Dim i As Integer, colCount As Integer, rngTest As Range
With ActiveSheet.UsedRange
ColCount = .Columns.Count
For i = 1 To ColCount
Set rngTest = .Columns(i)
'Do whatever you want to do with the range rngTest
Next
End With

--
Vasant


"wired" wrote in message
...
Hello.

I need some guidance here. I want to dimension a variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Iterate columns

Thanks, but, I don't want to loop through each cell...
I want to perform an action on each entire column.

What do I do in that case?

-----Original Message-----
Dim cell as Range
for each cell in Activesheet.UsedRange
' debug.print cell.address
Next

--
Regards,
Tom Ogilvy

"wired" wrote in

message
...
Hello.

I need some guidance here. I want to dimension a

variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option

Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Iterate columns

Thanks, but I don't want to loop through each CELL. I want
to perform an action on each entire column.

What would you suggest?

-----Original Message-----
Try something like

Dim Rng As Range
For Each Rng In Worksheets("Sheet1").UsedRange
Debug.Print Rng.Address
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"wired" wrote in

message
...
Hello.

I need some guidance here. I want to dimension a

variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option

Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Iterate columns

Try

Dim Col As Range
For Each Col In ActiveSheet.UsedRange.Columns
Debug.Print Col.Address
Next Col

or

Dim Col As Range
For Each Col In ActiveSheet.UsedRange.Columns
Debug.Print Col.EntireColumn.Address
Next Col


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"wired" wrote in message
...
Thanks, but I don't want to loop through each CELL. I want
to perform an action on each entire column.

What would you suggest?

-----Original Message-----
Try something like

Dim Rng As Range
For Each Rng In Worksheets("Sheet1").UsedRange
Debug.Print Rng.Address
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"wired" wrote in

message
...
Hello.

I need some guidance here. I want to dimension a

variable
and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option

Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



.



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Iterate columns

Just what I needed. Thanks much.

-----Original Message-----
Try

Dim Col As Range
For Each Col In ActiveSheet.UsedRange.Columns
Debug.Print Col.Address
Next Col

or

Dim Col As Range
For Each Col In ActiveSheet.UsedRange.Columns
Debug.Print Col.EntireColumn.Address
Next Col


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"wired" wrote in

message
...
Thanks, but I don't want to loop through each CELL. I

want
to perform an action on each entire column.

What would you suggest?

-----Original Message-----
Try something like

Dim Rng As Range
For Each Rng In Worksheets("Sheet1").UsedRange
Debug.Print Rng.Address
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"wired" wrote in

message
...
Hello.

I need some guidance here. I want to dimension a

variable
and use it in a "For Each" structure to iterate

through
the "used range" in a sheet. I'm using "Option

Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most

efficient
and need the least overhead? i.e. Should I just "Dim

as
Variant" or something else?

Your example code would be most appreciated. Thanks

in
advance.


.



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Iterate columns

Each entire column? Or that portion of each column that is within the range?

Alan Beban

wired wrote:
Thanks, but, I don't want to loop through each cell...
I want to perform an action on each entire column.

What do I do in that case?


-----Original Message-----
Dim cell as Range
for each cell in Activesheet.UsedRange
' debug.print cell.address
Next

--
Regards,
Tom Ogilvy

"wired" wrote in


message

...

Hello.

I need some guidance here. I want to dimension a


variable

and use it in a "For Each" structure to iterate through
the "used range" in a sheet. I'm using "Option


Explicit".

In this structure the variable has to be an object or
variant. Since there is no "Column" object already
defined, what should I use that would be most efficient
and need the least overhead? i.e. Should I just "Dim as
Variant" or something else?

Your example code would be most appreciated. Thanks in
advance.



.



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
SOLVER does not iterate / work BHatMJ Excel Discussion (Misc queries) 4 August 12th 09 10:42 PM
How can I iterate numbering when printing Jbird Excel Discussion (Misc queries) 1 August 18th 07 05:28 AM
Iterate Circular Reference Brandt Excel Discussion (Misc queries) 1 August 3rd 05 11:43 PM
Iterate though all open spreadsheets J Shrimps, Jr. Excel Worksheet Functions 1 March 10th 05 02:38 AM
How do I fill down formulas so they iterate in intervals other th. picklet222 Excel Worksheet Functions 2 December 18th 04 01:23 PM


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