ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Can I use variables in a Range function? (https://www.excelbanter.com/excel-discussion-misc-queries/25029-can-i-use-variables-range-function.html)

André - Brazil

Can I use variables in a Range function?
 
I´m triyng to use a variable content in a Range function without success,
Example:

LINHAREF = 10
Do While LINHAREF < 40
Lk = "K" + Str(LINHAREF)
MsgBox Range(Lk)
LINHAREF = LINHAREF +1
Loop


Duke Carey

You've DIMmed LINHAREF as an Integer, right?

Change it to: Lk = "K" & LINHAREF

Works for me.



"André - Brazil" wrote:

I´m triyng to use a variable content in a Range function without success,
Example:

LINHAREF = 10
Do While LINHAREF < 40
Lk = "K" + Str(LINHAREF)
MsgBox Range(Lk)
LINHAREF = LINHAREF +1
Loop


Dave Peterson

You can also use cells().

LINHAREF = 10
Do While LINHAREF < 40
MsgBox cells(linharef,"K").value
LINHAREF = LINHAREF +1
Loop

André - Brazil wrote:

I´m triyng to use a variable content in a Range function without success,
Example:

LINHAREF = 10
Do While LINHAREF < 40
Lk = "K" + Str(LINHAREF)
MsgBox Range(Lk)
LINHAREF = LINHAREF +1
Loop


--

Dave Peterson


All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com