0

Ok, I'm sure this question is really basic but all my searchers turn up complicated answers and I've been messing with VBA for about a day. I have two worksheets in an excel doc, I've created a button that I can click that invokes my macro that is just moving cells from one work sheet to another. But I need my macro to determine what row I am on. I'm using this:

r = ActiveCell.Row

to determine my row, but what would be the easiest way to use that variable in a range statement like this:

Range("A2").Select
Chrismas007
  • 6,085
  • 4
  • 24
  • 47
Jeff
  • 1
  • 1
  • 1
  • 1
  • Please clarify what you're asking, though. The way I read is: "how do I select the row from the variable `r`?" but it's not clear that is really your question. – David Zemens Feb 20 '15 at 17:25
  • 1
    [Stop using .select](http://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) – Chrismas007 Feb 20 '15 at 18:35

1 Answers1

8

You could use the Range method with the & operator to join the variable into a string:

Range("A" & r)

Alternately you can use the Cells method which takes arguments (Row, Column):

Cells(r, "A")
tigeravatar
  • 26,199
  • 5
  • 30
  • 38