Using variable for cell reference

B

bmurlidhar

how can I use variable for cell reference. IF i want to refere G9
cell and my variable mRow have value 9 how can use in excel macro
coding
 
S

Sheeloo

instead of using "G9" use "G" & mRow

eg
Range("G9") can be replaced by Range("G" & mRow)

Sub t()
MsgBox "Direct reference: G9=" & Range("G9")
mRow = 9
MsgBox "Indirect reference: G9= " & Range("G" & mRow)
End Sub
 
B

bmurlidhar

instead of using "G9" use "G" & mRow

eg
Range("G9") can be replaced by Range("G" & mRow)

Sub t()
MsgBox "Direct reference: G9=" & Range("G9")
mRow = 9
MsgBox "Indirect reference: G9= " & Range("G" & mRow)
End Sub

I want to give sum command i.e. =SUM(H1:H10) and my variable for
mFrow = 1 and mLrow = 10 how can i use variable in function
 
S

Sheeloo

you need to prepare the string H1:H10 using & operator to concatenate your
variables

share the line of code where you want to use the variables so that we can
tell you exactly what you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top