Button programming Run-time error '1004' with range

  • Thread starter Thread starter El_Pablo
  • Start date Start date
E

El_Pablo

Hi,

I've done a small program simulating a MonteCarlo sampling and I link
button to generate the chart.

I got this problem and I don't understant why...

Run-time error '1004':

Method 'range' of object '_Worksheet' failed

As you will see the code is very simple...


Code
-------------------

Private Sub btnGenerateChart_Click()
Dim iRepeatMonteCarlo As Integer
Dim iNbSeries As Integer

Dim rgSource As Range

iRepeatMonteCarlo = Range("'SimulationMonteCarlo'!D6").Value
iNbSeries = Range("'SimulationMonteCarlo'!D7").Value

rgSource = Range("'Stat Data'!B7:B96") ' Error 1004 here

'Set rgSource = Range("'Stat Data'!B7:B96") 'Error 1004 here

Call GenerateChart(rgSource, iRepeatMonteCarlo, iNbSeries)
End Sub

-------------------


The range is right because I use the same on the Chart_Activate event.

Thank you

Nic
 
You need the set statement as a range is an object (as opposed to a
variable). Additionally you need to reference the sheet and then the range
something lkie this...

set rgSource = sheets("Stat Data").Range("B7:B96")
 
Try this variation:
set rgSource = worksheets("stat data").Range("B7:B96")

When code is behind a worksheet module, then unqualified ranges belong to that
sheet that holds the code.

So you're really doing:

set rgSource = me.range("'stat data'!b7:b96")

And there isn't a range like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top