Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to declare a range using a variable

  Asked By: Robert    Date: Jan 12    Category: MS Office    Views: 1198
  

I am a rookie programmer so please bear with me.

I am trying to copy a range of cells and paste transposed in another
location in the same sheet. I need to do this 2000 times.

So lets say my data is in row A and the data I need to copy is range
("a1:a10"). I copy and paste transposed. Then I need to repeat for
range ("a11:a20"). Then a21 - a30, then, then, then,....

I want to use a For loop but I do not know how to call out the range
with the variable. For example ("a(i):a(i)+9") does not work.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Virgil Foster     Answered On: Jan 12

Try:
Sub pnahra()
For x = 1 To 200 Step 10
Range(Cells(x, 1), Cells(x + 9, 1)).Select
'do something here
Next x
End Sub

or:

Sub pnahra()
For x = 1 To 200 Step 10
Range("A" & x & ":A" & x + 9).Select
'do something here
Next x
End Sub

 
Didn't find what you were looking for? Find more on How to declare a range using a variable Or get search suggestion and latest updates.




Tagged: