Excel – Using a variable in a range statement in VBA excell macro


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:


Best Solution

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")