Mehod 'Range' of object '_Global" failed ...runtime error 1004

Copper Contributor

Although I have successfully ran similarly coded macros, this particular one is driving me crazy.  Below is the code,

 

Sub MoonSpeedNew()

Worksheets("Sheet4").Activate

Set r1 = Range("MoonVariables")
Set r2 = Range("day**bleep**spvalue")
Set r3 = Range("Resultvariables")

Dim Highlimit As Single
Dim oldlimit As Single
Dim Lowlimit As Single
Dim limit As Single
Dim Diff As Single
Dim imax As Integer
Dim i As Integer

 

The macro hangs up at the statement 

Set r1 = Range("MoonVariables")

with the above runtime error 1004

 

I checked the Range for MoonVariables under Name Manager in excel ...looks okay to me.

 

 

2 Replies

Sorry, I found my mistake.  I was referring to the wrong sheet.  My apologies. @Jmaheshri 

@Jmaheshri 

 

There may be one of the two issues....

 

  1. The named range has the worksheet scope and when you use that range in the code and code gets executed, the sheet which it belongs to is not the active sheet. e.g. if the named range was defined for Sheet1 and it has a worksheet scope and when you run the code, Sheet2 is active at that moment, the code will throw an error. OR
  2. The named range is made dynamic with the help of Indirect function or the named range returns an error.