GlenmoranUK
asked on
VB Dynamic Graph Excel Range Error
Hi experts,
I have a small vb script that I want to run to change the source data on a graph. No matter what I try I can not get the graph to accept the defined range. Here is the code:
The error is always shown on the last line.
Any help would really be appreciated.
I have a small vb script that I want to run to change the source data on a graph. No matter what I try I can not get the graph to accept the defined range. Here is the code:
intLastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
intLastCol = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
Sheets("Graph").Select
ActiveChart.ChartArea.Select
ActiveChart.SetSourceData Source:=Sheets("Chart Data").Range(Cells(5, 1), Cells(intLastRow, intLastCol))
The error is always shown on the last line.
Any help would really be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The Cells(5, 1) in your code refers to the cells of the active sheet. Being the Graph sheet, which doesn't have cells, hence the error.
ASKER
Fantastic.. That has had me going round in circles for a good couple of hours.. :o)
Many thanks for the code and more importantly the explanation.
Many thanks for the code and more importantly the explanation.