+ Reply to Thread
Results 1 to 2 of 2

Using VBA code to change Chart Data Series

  1. #1
    WilliamI
    Guest

    Using VBA code to change Chart Data Series

    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

  2. #2
    WilliamI
    Guest

    RE: Using VBA code to change Chart Data Series

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

    "WilliamI" wrote:

    > 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


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1