ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range question (https://www.excelbanter.com/excel-programming/311406-range-question.html)

strataguru[_19_]

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


Jim Thomlinson[_3_]

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



Tom Ogilvy

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





All times are GMT +1. The time now is 08:48 PM.

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