LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Problem using Range objects

Hi,

in a subroutine I'm writing, I'm trying to create a reference to the
first 5 cells of the second column of a Range object, which is *not*
on the active sheet. I have two questions:

1. How would you do that?
2. I tried writing two different subroutines which should do the same
job, but one doesn't work and I don't know why .
-------------------------------------------------------------------------------------
Sub test()
Dim MyRange As Range
Dim sht As Worksheet

' Set the work sheet
Sheets("Sheet1").Activate

' Set range
With sht
Set MyRange = .Range(.Cells(3, 3), .Cells(57, 6))
End With

Call ValidProcedure(MyRange)
'Call InvalidProcedure(MyRange)

End Sub
----------------------------------------------------------------------------------------------------------
Sub ValidProcedure(MyRange As Range)
Dim MySubRange As Range

' MyRange is a range on sheet "Sheet1"

Sheets("Sheet2").Activate

Set MySubRange = Range(MyRange.Cells(1, 2), MyRange.Cells(5, 2))

End Sub
---------------------------------------------------------------------------------------------------------
Sub InvalidProcedure(MyRange As Range)
Dim MySubRange As Range

' MyRange is a range on sheet "Sheet1"

Sheets("Sheet2").Activate

With MyRange
Set MySubRange = .Range(.Cells(1, 2), Cells(5, 2))
End With

End Sub
--------------------------------------------------------------------------------------------------------

In the second subroutine, MySubRange points to a range which is not
the one desired. Can you help me understanding what's happening?
Thanks,

Best Regards

Sergio
 
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
Problem with VB Objects in Excel Jason Zischke Excel Programming 5 August 7th 09 07:40 PM
insert objects problem ARGT Excel Discussion (Misc queries) 1 July 21st 08 12:28 PM
How to get individual range objects from a set of range objects? Dev Excel Programming 4 February 4th 07 12:14 AM
Range objects (?) Bill[_19_] Excel Programming 1 December 23rd 03 02:37 PM
Cannot use range objects jason Excel Programming 7 November 27th 03 03:00 AM


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