LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Weird range property behaviour

Ahhh.

Now I see. Thanks very much Tom.

Best regards,

Gareth

"Tom Ogilvy" wrote in message
...
Sub Temp()
Dim rng0 As Range, rng1 As Range, y As Integer
y = 3

Set rng0 = Worksheets(1).Cells(y, 1)
Set rng1 = Range(rng0(1), rng0(2))

Debug.Print "Top row rng0: " & rng0.Row
Debug.Print "Top row rng1: " & rng1.Row

End Sub

will give you the same top row.

Range(rng0(1), rng0(2))
is relative to the top left cell of the spread sheet.

rng0.Range(rng0(1), rng0(2))
is relative to the location of rng0

rng0 is A3
rng0(1) is A3
rng0(2) is A4

frm the immediate window:
set rng0 = cells(3,1)
? rng0.address, rng0(1).address, rng0(2).address
$A$3 $A$3 $A$4

Range("A3","A4") refers to A3:A4 - the addresses are absolute/relative

to
A1

rng0.Range("A3","A4") says, from A3, step down 3 rows (counting A3 as the
first) and address a two cell vertical range.

--
Regards,
Tom Ogilvy



"Gareth Thackeray" wrote in message
...
Hi Tom,

Thanks for the help Tom, I used Resize instead to accomplish what I

wanted

I still don't quite understand what happens when you use

rng.Range(cell1,
cell2). For your interest, a sub explaining my confusion is below:

Sub Temp()
Dim rng0 As Range, rng1 As Range, y As Integer
y = 3

Set rng0 = Worksheets(1).Cells(y, 1)
Set rng1 = rng0.Range(rng0(1), rng0(2))

Debug.Print "Top row rng0: " & rng0.row
Debug.Print "Top row rng1: " & rng1.row

End Sub

I would expect the top row in either case to be y, but instead the top

row
of rng1 always seems to be 2y -1.

FYI, what I'm actually trying to do is to get a range that consists of

rows
r0 to r1 of an existing range.

Best regards,

Gareth








 
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
Weird Excel diagram behaviour Marcus Charts and Charting in Excel 1 March 14th 10 10:21 PM
Weird VBA Behaviour msnyc07 Excel Worksheet Functions 13 February 15th 10 08:04 AM
Weird WindowsMediaPlayer behaviour teepee[_3_] Excel Discussion (Misc queries) 1 October 26th 08 11:20 PM
Excel2000: Weird behaviour in VBA Arvi Laanemets Excel Discussion (Misc queries) 3 February 1st 06 02:14 PM
Excel2000: Weird chart behaviour Arvi Laanemets Excel Discussion (Misc queries) 2 September 6th 05 07:48 AM


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