set range

  • Thread starter Thread starter Excel User
  • Start date Start date
E

Excel User

Hi,

I keep getting an error with the following:

MyRangeOne = Worksheets("sheet2").Range("Z12:AG12")
MyRangeTwo = Worksheets("sheet2").Range("Z13:AG500")

Is this not the way to set a range?

Thanks
 
Hi,

I keep getting an error with the following:

MyRangeOne = Worksheets("sheet2").Range("Z12:AG12")
MyRangeTwo = Worksheets("sheet2").Range("Z13:AG500")

Is this not the way to set a range?

Thanks


Try this:

Set MyRangeOne = Worksheets("sheet2").Range("Z12:AG12")
Set MyRangeTwo = Worksheets("sheet2").Range("Z13:AG500")

Hope this helps / Lars-Åke
 
Precede your statements with the keyword 'Set' as in Set MyRangeOne =
Worksheets("sheet2").Range("Z12:AG12")
 
Thanks for your reply, I've changed the statement as suggested but receive
an error message is

Compile error:
'Object required'

Any ideas?
 
make sure that you have
OPTION EXPLICIT
at the top of your module

then
DIM MyRangeOne as Range
DIM MyRangeTwo as Range

SET MyRangeOne = Worksheets("sheet2").Range("Z12:AG12")
SET MyRangeTwo = Worksheets("sheet2").Range("Z13:AG500")
 
Patrick,

Thanks for your reply, I'm picking up someone's script, it seems that
MyRangeOne & MyRangeTwo are set as DIM MyRangeOne as String.

Thanks!
 
Back
Top