Issue with setting chart data

Hi there,

 

I am struggling with my Macro in which I am attempting to have a chart display an active range. To begin with, I have a repeated IF statement which basically decides which cells will be selected dependant on the value of a cell (Set ab = Cells(57,19)). See example below…

 

Dim wb As Workbook

Dim ws As Worksheet

Set wb = ActiveWorkbook

Set ws = Sheets(“Parameters”)

wb.Activate

ws.Select

Dim ab As Range

Set ab = Cells(57, 19)

Dim rng As Range

Set selrange = selection

If ((ab < 2) And (ab >= 1)) Then

Range(“g77:j90”).Select

End If

 

If ((ab < 3) And (ab >= 2)) Then

Range(“g77:j95”).Select

End If

 

If ((ab < 4) And (ab >= 3)) Then

Range(“g77:j100”).Select

End If

 

Following this I want “chart 6” to display this selection as the source data.  

 

Dim CHARTDATA As Range

Set CHARTDATA = selection

 

 

Chart6.SetSourceData Source:=CHARTDATA, PlotBy:=xlColumns

 

However, I recieve the error message “run-time error “424”: object required”. I believe this is due to the selected range being deselected once chart 6 is being altered? To fix this I tried storing the range selection to CHARTDATA, but obviously this hasn’t worked neither. 

Any and all ideas are welcome, and apologies if this is a repeated and very basic question (I’m totally new to VBA).

 

Thanks in advance.

By: Niall

Leave a Reply

Your email address will not be published. Required fields are marked *