Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Cell References Within a Loop

Status
Not open for further replies.

sbev

Programmer
May 30, 2001
27
CA
I am learning VBA for use with Excel and have run into the following problem:
For count = 1 To 20
...
Range("Ax").Select
[x = 185*(count-2)+ 1]
...
Range("Ax:Ay").Select
Range("Dz").Select
[x as above, y = 185*(count-1),z = 185*(count-1)+1]
...

How do I set up x, y and z so that the cell references keep incrementing within the loop? Also, beside count what will have to be dimensioned?

Any help appreciated.

Sbev
 
Hi,
Code:
    For Count = 1 To 20
    '...
        x = 185 * (Count - 2) + 1
        y = 185 * (Count - 1)
        z = 185 * (Count - 1) + 1
        Cells(x, "A").Select
        'OR
        Cells(x, 1).Select
        
        Range(Cells(x, "A"), Cells(y, "A")).Select
        Cells(z, "D").Select
        'OR
        Cells(z, 4).Select
        [x as above, y = 185*(count-1),z = 185*(count-1)+1]
    Next
Try NOT selecting ranges as much as possible. Most calculations and assignments can be done without selecting sheets and ranges.

Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
Hi Skip,

Thanks, it works great.

Sbev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top