Using a variable in a range statement in VBA excell macro

陌路散爱 提交于 2021-02-05 09:32:28

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/28634626/using-a-variable-in-a-range-statement-in-vba-excell-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!