2
Set rng = Worksheets("Sheet1").Range("B2")

I have the above and would like to run a loop that changes the range I use/evaluate. I have tried variations of the following.

for x = 2 to 10
Set rng = Worksheets("No-Funding").Range(x & "2")
Next X

I have done some investigating and found this other Stack Overflow: Excel VBA Looping formula to change Range I can not make sense of it in this situation though.

My code will not work if it uses cells either, I have tried that and can only make it work with Range. Thanks for any help provided!

1
  • So, using Cells() in your Range() doesn't work? So, what happens when you try something like Set rng = worksheets("No-Funding").Range(cells(1,1),Cells(x,2)) (What range are you trying to get? Right now, your rng will equate to 22, 32. Is that supposed to be a column, or row? Commented Jul 28, 2015 at 14:15

3 Answers 3

4

For a strictly numerical increment try,

Set rng = Worksheets("No-Funding").Cells(x, 2)

An xlA1 style reference can be achieved by factoring in the ASCII character.

Set rng = Worksheets("No-Funding").Range(Chr(64 + x) & 2)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sir. This is simplicity effective and genius. I'll mark as the answer as soon as the timer passes by
1

Try this:

For x = 2 To 10
    Set rng = Worksheets("No-Funding").Cells(2, x)
Next x

As far as I know it is no matter for VBA if you use function .Range or .Cells, since both of them return object or Range type.

Comments

1

Use

Set rng = Worksheets("Sheet1").Range("B2").Offset(0,x)

to move to a different column. Better yet

Dim values as Variant, rng as Range
Set rng = Worksheets("Sheet1").Range("B2").Resize(10,1)
values = rng.Values2

For i=1 to 10
   values(i,1) = 2*values(i,1)
Next i

rng.Values2 = values

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.