Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Describing a Range with Variables

Hi

I have the following problem:
I want to select a certain Range depending on the value of a variable

e.g.
I habe a variable called nr (current value = 1)
I want to replace:

Range("O1:O200").Select

with:

" Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"

How can you wright that in VBA?

Mazo

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Describing a Range with Variables

Hi Mazo,

You are almost there! Try:

Dim rng As Range

Set rng = Range(Cells(1, 14 + i), Cells(200, 14 + i))


---
Regards,
Norman



"mazo" wrote in message
oups.com...
Hi

I have the following problem:
I want to select a certain Range depending on the value of a variable

e.g.
I habe a variable called nr (current value = 1)
I want to replace:

Range("O1:O200").Select

with:

" Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"

How can you wright that in VBA?

Mazo



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Describing a Range with Variables

Another way:

Dim myRng as range
dim nr as long
nr = 1 'or something

set myrng = activesheet.cells(1,14+nr).resize(1,200)

..resize(1,200) means to take the original range (cells(1,14+nr) and resize it to
1 row by 200 columns.





mazo wrote:

Hi

I have the following problem:
I want to select a certain Range depending on the value of a variable

e.g.
I habe a variable called nr (current value = 1)
I want to replace:

Range("O1:O200").Select

with:

" Range [ Cells(1,(14+nr)) to Cells(200,(14+nr)) ]"

How can you wright that in VBA?

Mazo


--

Dave Peterson
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
Adding a range with three variables Saul Excel Discussion (Misc queries) 4 July 25th 08 02:21 PM
How to hyperlink 800 documents to spreadsheet describing each docu Coltten Excel Worksheet Functions 1 May 15th 08 07:58 PM
Can I use variables in a Range function? André - Brazil Excel Discussion (Misc queries) 2 May 5th 05 10:39 PM
Using variables to select a range Marc[_14_] Excel Programming 1 November 29th 03 02:36 AM
Range Variables Daniel[_7_] Excel Programming 1 November 20th 03 05:45 AM


All times are GMT +1. The time now is 05:32 PM.

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"