Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ade ade is offline
external usenet poster
 
Posts: 16
Default Problem with Worksheets v Ranges 'Again'

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Problem with Worksheets v Ranges 'Again'

Range2 is a variable, a range object variable, not a property of
Worksheets("ColumnSplits"), so don't qualify it as such, i.e.

With Worksheets("ColumnSplits")
.Range2.Select
End With

should just be

Range2.Select

BTW, you can define it a little simpler

Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)

becomes

Set Range1 = Range("A" & StartRange1 & ":A" & EndRange1)

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ade" wrote in message
...
I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there
any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to
me,
for example in my code I can not see why the line '.Range2.Select' will
not
work, it seems like the obvious solution to me.

Cheers



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Problem with Worksheets v Ranges 'Again'

Range2 is a variable in your code and is not a member of the WorkSheets
object, which is how your code is attempting to access it.

You should use it just like you do with your Range1 variable.

ie
Range2.select


"Ade" wrote:

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem with Worksheets v Ranges 'Again'

Since Range2 is already a range, it comes with all the properties that range
objects have. Including its parent. (The parent of the range is the worksheet
that owns it.)

So you don't respecify the worksheet when you refer to Range2 (Range2 already
knows where it belongs).

This won't work:

With Worksheets("ColumnSplits")
.Range2.Select
End With


But this will

Worksheets("ColumnSplits").select
range2.select

(You have to be on the worksheet to select a range.)


On the other hand, this kind of thing will work:

With Worksheets("ColumnSplits")
.Select 'still needed
.range("a1:b99").select
End With



..range property is different than your Range2 variable.


Ade wrote:

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55

Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Problem with Worksheets v Ranges 'Again'

When you 'Set' a range variable it refers to the entire area you referenced
on to right side of the = symbol. So Range2 already refers to A2:A56 on
sheet ColumnSplits.
When you say
With Worksheets("ColumnSplits")
.Range2.Select
End With
you are actually saying
Worksheets("ColumnSplits").Range(Worksheets("Colum nSplits").Range("A2:A56").Select
which confuses Excel since there is no worksheet ColumnSplits within
worksheet ColumnSplits.

Also, Excel doesn't like trying to select a range unless the sheet it is on
is already selected/active. Your code would probably work like this:
Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
Worksheets("ColumnSplits").Activate ' or .Select
Range2.Select
End Sub

When you want to set a range variable (as Range1) to a range on the current
worksheet, use the same format you did in your code, and when you need it to
reference a range in another workbook/worksheet do as you did with Range2
(with specified workbook also if you need to reference worksheet & range in a
different, open workbook). Hope that helps some.

"Ade" wrote:

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Problem with Worksheets v Ranges 'Again'

Hi,

Range2 is not a property of the Worksheet object. Rather, it's a variable
that you defined, just like Range1. So, you use it also just like how you
used Range1.

Range2.Select




--
Hope that helps.

Vergel Adriano


"Ade" wrote:

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers

  #7   Report Post  
Posted to microsoft.public.excel.programming
ade ade is offline
external usenet poster
 
Posts: 16
Default Problem with Worksheets v Ranges 'Again'

Thank you all for your help, I think I have confused 'selecting' the range on
a different worksheet with 'working with' a range on a different worksheet as
I do not want to actually have to make the VBA code change between worksheets.

"Vergel Adriano" wrote:

Hi,

Range2 is not a property of the Worksheet object. Rather, it's a variable
that you defined, just like Range1. So, you use it also just like how you
used Range1.

Range2.Select




--
Hope that helps.

Vergel Adriano


"Ade" wrote:

I seem to have a lot of difficulty using / selecting ranges that i have
defined on different Worksheets. I have read that you need to explictly
define the range which I often try to do - with usually poor results as I
always get the syntax wrong.
My current problem occurs in the following code module :-

Dim Range1 As Range
Dim Range2 As Range
Dim StartRange1 As Integer
Dim EndRange1 As Integer
Dim StartRange2 As Integer
Dim EndRange2 As Integer
Const RangeSize As Integer = 55


Sub Init()
StartRange1 = 3
EndRange1 = 57
StartRange2 = 2
EndRange2 = 56
Set Range1 = Range("A" & StartRange1 & ":" & "A" & EndRange1)
Set Range2 = Worksheets("ColumnSplits").Range("A" & StartRange2 & ":" &
"A" & EndRange2)
Range1.Select
With Worksheets("ColumnSplits")
.Range2.Select
End With

End Sub

Error : 'Object does not support this property or method' at the line near
the bottom '.Range2.Select'.

Anyone who can suugest the correct code to Select Range2? Also is there any
usefull methods for figuring out which code syntax you have to use when
working with ranges on different Worksheets as it never seems obvious to me,
for example in my code I can not see why the line '.Range2.Select' will not
work, it seems like the obvious solution to me.

Cheers

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
Ranges spanning worksheets RD Wirr Excel Worksheet Functions 0 November 22nd 06 07:04 AM
Copying Name Ranges along with Worksheets cratediggah[_2_] Excel Programming 1 August 16th 06 05:49 PM
worksheets and ranges David Gerstman Excel Programming 2 August 7th 06 09:57 PM
Worksheets, Ranges & Unknowns Alex Excel Programming 0 December 8th 04 10:47 PM
Comparing Ranges in two worksheets JeffFinnan Excel Programming 4 January 6th 04 11:30 PM


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