Cant refer to graph from other sheet?
Hi everybody!
I want to refer to a graph from my sheet called "Overview", the graph is located in a sheet called "Historic". The code is the following:
Dim shtHis As Worksheet: Set shtHis = Sheets("Historic")
Dim lInterval As Long: lInterval = shtHis.Range("A2").End(xlDown).Row
shtHis.ChartObjects("Chart 11").Activate
ActiveChart.SetSourceData Source:=shtHis.Range("A1:A" & lInterval & ",B1:B" & lInterval)
The code is located in a module for the whole workbook.
When i push the button to run the code in "overview" i get a bug: "Run-time error "1004": Method "range" of Object" worksheet" failed.
Im not very familiar with graphs within VBA, am i refering to it the wrong way?
- When i press f8 within the vba window, in compile mode, the code works just fine.
Hope someone can help! Cheers!