Link to home
Start Free TrialLog in
Avatar of Jenkins
JenkinsFlag for United States of America

asked on

Reference a cell using a variable

I'm trying to use a variable value in a macro to reference a cell.   For example, I currently some code that looks like this:

If Cells( 5,10).value = "" then
   msgbox "cell J5 is empty"

Let's say I have an Integer variable named MyVariable and I assign a value of 5 to it.

I'm trying to code something like:

If Cells(MyVariable,10).Value = "" then
   msgbox "cell J5 is empty"

but I can't get it to work.   I don't care about using the "Cells" reference method. I'm just trying to use any method where a cell can be referenced using a variable like the one I've drescribed above.

Thank you
Avatar of Norie
Norie

That code looks fine to me, Cells(MyVariable, 10) should refer to J5 on the active sheet.

What problems are you having?
ASKER CERTIFIED SOLUTION
Avatar of Fredd
Fredd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course - this also works on a single line
If Cells(n, 10).Value = "" Then MsgBox "empty"