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


Hi,

I'd like to select a Range in column 1 from Row 1 to 7. Another tim
it may be some other random column for a difference range of rows.

So I'm wondering - how can I numerically select a range. I can't us
hard coded values like:

Range("A1:A7").Select

How can I select my Range dynamically for a ad-hoc group of cells?

Thanks in advanc

--
stratagur
-----------------------------------------------------------------------
strataguru's Profile: http://www.excelforum.com/member.php...nfo&userid=131
View this thread: http://www.excelforum.com/showthread.php?threadid=26337

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Range question

This might be a little funkier than you wanted but here goes...

copy everything below here to a new workbook module

'This function will set a range
public function GetRange (byval strSheetName as string, byval lngFirstRow as
long, byval lngLastRow as long) as range

set GetRange = sheets(strsheetname).range(lngFirstRow & ":" & lngLastRow)

end function

'Now to use the function...
sub test
dim rngMyRange as range

set rngmyrange = getrange("Sheet1", 3, 10)

'Now you have a range object with all the associated properties and methods.

rngMyRange.Select

end sub

'Hope this helps...

"strataguru" wrote:


Hi,

I'd like to select a Range in column 1 from Row 1 to 7. Another time
it may be some other random column for a difference range of rows.

So I'm wondering - how can I numerically select a range. I can't use
hard coded values like:

Range("A1:A7").Select

How can I select my Range dynamically for a ad-hoc group of cells?

Thanks in advance


--
strataguru
------------------------------------------------------------------------
strataguru's Profile: http://www.excelforum.com/member.php...fo&userid=1313
View this thread: http://www.excelforum.com/showthread...hreadid=263374


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range question

Sub AAABBB()
Dim rng As Range
For i = 1 To 10
Set rng = Cells(Int(Rnd() * 15 + 1), _
Int(Rnd() * 10 + 1)).Resize( _
Int(Rnd() * 20 + 1), 1)
Debug.Print rng.Address
rng.Select
Next i
End Sub

produced:

$F$13:$F$29
$C$14:$C$33
$C$15:$C$28
$J$2:$J$12
$F$1:$F$14
$H$2:$H$4
$C$1:$C$6
$J$5:$J$12
$C$7:$C$26
$G$3:$G$6



as an example.

--
Regards,
Tom Ogilvy



"strataguru" wrote in message
...

Hi,

I'd like to select a Range in column 1 from Row 1 to 7. Another time
it may be some other random column for a difference range of rows.

So I'm wondering - how can I numerically select a range. I can't use
hard coded values like:

Range("A1:A7").Select

How can I select my Range dynamically for a ad-hoc group of cells?

Thanks in advance


--
strataguru
------------------------------------------------------------------------
strataguru's Profile:

http://www.excelforum.com/member.php...fo&userid=1313
View this thread: http://www.excelforum.com/showthread...hreadid=263374



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 question in '97 Adam Kroger Excel Discussion (Misc queries) 10 December 12th 05 03:44 AM
Range question in VB rohnds Excel Programming 3 July 14th 04 09:51 AM
Range Question Ray Batig Excel Programming 4 January 31st 04 05:01 AM
If Range.Name question Otto Moehrbach[_5_] Excel Programming 8 November 30th 03 11:05 PM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 06:15 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"