Redefine UsedRange property of Worksheet Object

E

ExcelMonkey

I am using the following code to loop through the UsedRange of worksheet:

For Each Cell In sh.UsedRange

I want to replace the .UsedRange property of the worksheet with a new range
via string variable called WorkingRange which has a new range address i it.
How do I do that?

Thanks

EM
 
S

sebastienm

Hi
Say WorkingRange is the address as a string

For Each Cell In sh.Range(WorkingRange).cells

Next
 
O

Otto Moehrbach

If the new range address is a string, something like this might work for
you:
For each Cell in Range(WorkingRange)
HTH Otto
 
R

Rick Rothstein \(MVP - VB\)

Dim a variable of Type Range and Set the range you want to it before
executing the loop.

Dim Rng As Range
Dim Cel As Range
Set Rng = sh.UsedRange
For Each Cel In Rng
....
Next
.....
.....
Set Rng = Range(WorkingRange)
For Each Cel In Rng
...
Next

By the way, by "string variable called WorkingRange", I am assuming you
meant an assignment that looks like this... "A1:E5" (so that it would be
referenced as shown in my code by using it as the argument to the Range
command.

Rick
 

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

Top