Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variables in a cell reference Carpe Diem[_2_] Excel Programming 5 September 22nd 06 10:14 PM
using variables to reference sheets marksince1984[_5_] Excel Programming 6 June 15th 06 11:29 PM
reference variables correctly? Kieran1028[_2_] Excel Programming 1 October 27th 04 08:53 PM
reference variables correctly? Kieran1028[_3_] Excel Programming 0 October 27th 04 08:00 PM
Using variables to reference columns in VBA aktiv Excel Programming 3 May 24th 04 04:46 AM


All times are GMT +1. The time now is 03:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"