Using VBA code to change Chart Data Series

W

WilliamI

On a worksheet, I have a List Box Control (lbProfitICSales) with a
ListFillRange named "Profit_Ind_Cd_Sales". When selecting an item in the List
Box, I want to change the x and y data series in the single chart on the
"Profit-Ind Cd Sales" worksheet. I don't understand why the following code
does not work- I always get an "object does not support this property or
method". Help lookup indicates this code should work.

Private Sub lbProfitICSales_Change()

Dim strwksht As String

strwksht = Application.ActiveSheet.Name

'Worksheets("Review").Unprotect
'Worksheets(strwksht).Activate

With Worksheets(strwksht).ChartObjects(1).Chart
.HasTitle = True
.ChartTitle.Text = "Profit by Industry Code Sales Regression"

Select Case lbProfitICSales
Case "Comb GP"
.SeriesCollection(1).Name = "Comb GP"
.SeriesCollection(1).XValues = Worksheets(strwksht)!Range("C10:C65")
.SeriesCollection(1).Values = Worksheets(strwksht)!Range("U10:U65")

Case "Comb PAD"
.SeriesCollection(1).Name = "Comb PAD"
.SeriesCollection(1).XValues = Worksheets(strwksht)!Range("E10:E65")
.SeriesCollection(1).Values = Worksheets(strwksht)!Range("E10:E65")

Case "Comb OP"
.SeriesCollection(1).Name = "Comb OP"
.SeriesCollection(1).XValues = Worksheets(strwksht)!Range("G10:G65")
.SeriesCollection(1).Values = Worksheets(strwksht)!Range("W10:W65")

End Select
End With
End Sub
 
W

WilliamI

I found the answer to my own question - syntax issue with Worksheet.Range
that I overlooked
 

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

Top