MarkH001


I have looked around the web and cannot find a solution .. hope somebody can help..

I consistantly get run-time error '1004' Method 'Range' of object '_Global' failed when I hit the Range command.

The refedit contanis text somthing like (select a range of cells with my mouse)

'Sheet1'!R5C2:R15C2

But I cannot turn that into useable information.

My code is launched from a command button through a Form

Public Sub CommandButton1_Click()

Dim freqRange As Range
Dim respRange As Range
Dim psdRange As Range

freqRange = Range(UserForm1.RefEdit1.Value) 'error occurs here!
respRange = Range(UserForm1.RefEdit2.Value)
psdRange = Range(UserForm1.RefEdit3.Value)

TextBox1.Value = (Module1.sumpsd(freqRange, respRange, psdRange)) 'pass data to program
TextBox2.Value = (Module1.Meanfreq(freqRange, respRange, psdRange)) 'pass data to program

End Sub

Any ideas Thank you in advance!

Mark




Re: run-time error '1004' Method 'Range' of object '_Global' failed wen using refedit

Andy Pope


Hi,

I get Error 91. Object variable or With block variable not set.
If you want a range reference you will need to use SET

Set freqRange = Range(UserForm1.RefEdit1.Value)

I'm also no sure how/why your commandbutton's click event is Public


If I use a button from the Forms toolbox I can get the error is the returned value is "".
Is the form still loaded when you run the code If not referencing the refedit will cause the form to load and the default value of the refedit may well be "" or blank.

Can you use the debugger to check the value of RefEdit1.