Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using variables in the Range command

Usually the Range method looks like:
Range("A1:C50")

In my case, the first and last column are variables. How can I still
use the Range method? I need to find a command to define my range
like:

dim rgRange as range

rgRange = sheetname.range( (row i, column j): (row m, column n) )

any help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Using variables in the Range command

Sub test()

Dim Row1 As Long
Dim Col1 As Long
Dim Row2 As Long
Dim Col2 As Long
Dim rngRange As Range

Set rngRange = _
Sheets(1).Range(Cells(Row1, Col1), _
Cells(Row2, Col2))

End Sub

RBS


"Chi Man Wong" wrote in message
om...
Usually the Range method looks like:
Range("A1:C50")

In my case, the first and last column are variables. How can I still
use the Range method? I need to find a command to define my range
like:

dim rgRange as range

rgRange = sheetname.range( (row i, column j): (row m, column n) )

any help?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Using variables in the Range command

A minor modification of RBS's solution--just in case the activesheet wasn't
sheets(1):

Sub test()

Dim Row1 As Long
Dim Col1 As Long
Dim Row2 As Long
Dim Col2 As Long
Dim rngRange As Range

col1 = 3
row1 = 1
col2 = 5
row2 = 7

with sheets(1)
Set rngRange = .Range(.Cells(Row1, Col1), .Cells(Row2, Col2))
end with

End Sub

Note the extra dots with the .cells().

Chi Man Wong wrote:

Usually the Range method looks like:
Range("A1:C50")

In my case, the first and last column are variables. How can I still
use the Range method? I need to find a command to define my range
like:

dim rgRange as range

rgRange = sheetname.range( (row i, column j): (row m, column n) )

any help?


--

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
Range of variables with the 'floor' command included ReelDesigner Excel Worksheet Functions 0 January 26th 06 04:05 PM
find command using variables eyecalibrate[_6_] Excel Programming 1 September 24th 04 12:18 AM
Input Command with Mainframe file and multiple variables BSchwerdt[_2_] Excel Programming 4 December 17th 03 11:47 PM
Range Variables Daniel[_7_] Excel Programming 1 November 20th 03 05:45 AM
Variables in command lines Russell[_2_] Excel Programming 0 July 9th 03 11:34 AM


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

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

About Us

"It's about Microsoft Excel"