ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   reference with variables (https://www.excelbanter.com/excel-programming/428934-reference-variables.html)

Saladin Andreas[_2_]

reference with variables
 
range (e.g. for printarea selection) is normally noted like e.g.: "B2:S60"
Instead of the numbers I would like to use variables to replace numbers e.g.
integer variable.

It does not work to do it this way "B2:Sy"
nor this way "B2:S"y""

It seems that there has to be a letter and a number as reference

How to solve this?

Jacob Skaria

reference with variables
 
Try below

Dim y as Long

y = 60
Range("B2:S" & y)


If this post helps click Yes
---------------
Jacob Skaria


"Saladin Andreas" wrote:

range (e.g. for printarea selection) is normally noted like e.g.: "B2:S60"
Instead of the numbers I would like to use variables to replace numbers e.g.
integer variable.

It does not work to do it this way "B2:Sy"
nor this way "B2:S"y""

It seems that there has to be a letter and a number as reference

How to solve this?


Patrick Molloy

reference with variables
 
Jacob shows one way

instead of RANGE(), you could use CELLS()

dim rw1 as long
dim cl1 as string
dim rw2 as long
dim cl2 as string

rw1=2
cl1="B" ' or 2 with cl1 DIM as a LONG
rw2=60
cl2="S" ' or 19 with cl2 DIM as a LONG

Range(Cells(rw1.cl1),Cells(rw2,cl2))

"Saladin Andreas" wrote in
message ...
range (e.g. for printarea selection) is normally noted like e.g.: "B2:S60"
Instead of the numbers I would like to use variables to replace numbers
e.g.
integer variable.

It does not work to do it this way "B2:Sy"
nor this way "B2:S"y""

It seems that there has to be a letter and a number as reference

How to solve this?




All times are GMT +1. The time now is 07:27 PM.

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