Link to home
Start Free TrialLog in
Avatar of GlenmoranUK
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:

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))

Open in new window


The error is always shown on the last line.

Any help would really be appreciated.

ASKER CERTIFIED SOLUTION
Avatar of Nico Bontenbal
Nico Bontenbal
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of GlenmoranUK
GlenmoranUK

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.