set range

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
 
L

Lars-Åke Aspelin

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
 
H

Howard31

Precede your statements with the keyword 'Set' as in Set MyRangeOne =
Worksheets("sheet2").Range("Z12:AG12")
 
E

Excel User

Thanks for your reply, I've changed the statement as suggested but receive
an error message is

Compile error:
'Object required'

Any ideas?
 
P

Patrick Molloy

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")
 
E

Excel User

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!
 
Top