Results 1 to 5 of 5

Thread: Change Chart Title According To Source Data Selection

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0

    Change Chart Title According To Source Data Selection

    What is required to change in the Chart code so that the charts have the below

    1. Y-Axis showing the Hours
    2. Each column showing the Name underneath and the Value on top of the column

    Regards

    Terry
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Replace the original code in the userform with this

    Code:
    Private Sub CommandButton1_Click()
    
        Dim lng As Long
        Dim ser As Series
        
        For lng = 0 To Me.ListBox1.ListCount - 1
            If Me.ListBox1.Selected(lng) Then
                With Worksheets("Charts")
                    With .Shapes.AddChart.Chart
                        .Parent.Top = Worksheets("Charts").ChartObjects.Count * .Parent.Height + 10 - .Parent.Height
                        .ChartType = xlColumnClustered
                        .SetSourceData Source:=Worksheets("DATA").Range("" & Worksheets("DATA").Range(Replace(Me.ListBox1.List(lng), "-", "")).Address & "," & Worksheets("DATA").Range(Replace(Me.ListBox1.List(lng), "-", "")).Offset(, Me.ComboBox1.ListIndex + 1).Address)
                         .Parent.Width = .Parent.Width * 2
                        .ChartGroups(1).GapWidth = 50
                        .ApplyDataLabels
                        For Each ser In .SeriesCollection
                            With ser.DataLabels
                                .ShowSeriesName = True
                                .Position = xlLabelPositionInsideBase
                                .Separator = "" & Chr(10) & ""
                            End With
                        Next ser
                    End With
                End With
            End If
        Next lng
        Application.Goto Worksheets("Charts").Range("A1")
        Unload Me
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    In fact, use this one for the vertical axis title also

    Code:
    Private Sub CommandButton1_Click()
    
        Dim lng As Long
        Dim ser As Series
        
        For lng = 0 To Me.ListBox1.ListCount - 1
            If Me.ListBox1.Selected(lng) Then
                With Worksheets("Charts")
                    With .Shapes.AddChart.Chart
                        .Parent.Top = Worksheets("Charts").ChartObjects.Count * .Parent.Height + 10 - .Parent.Height
                        .ChartType = xlColumnClustered
                        .SetSourceData Source:=Worksheets("DATA").Range("" & Worksheets("DATA").Range(Replace(Me.ListBox1.List(lng), "-", "")).Address & "," & Worksheets("DATA").Range(Replace(Me.ListBox1.List(lng), "-", "")).Offset(, Me.ComboBox1.ListIndex + 1).Address)
                         .Parent.Width = .Parent.Width * 2
                        .ChartGroups(1).GapWidth = 50
                        .ApplyDataLabels
                        .SetElement (msoElementPrimaryValueAxisTitleRotated)
                        .Axes(xlValue, xlPrimary).AxisTitle.Text = "Hour"
                        For Each ser In .SeriesCollection
                            With ser.DataLabels
                                .ShowSeriesName = True
                                .Position = xlLabelPositionInsideBase
                                .Separator = "" & Chr(10) & ""
                            End With
                        Next ser
                    End With
                End With
            End If
        Next lng
        Application.Goto Worksheets("Charts").Range("A1")
        Unload Me
        
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0
    Thanks

    Would it be achievable to create the charts like the attached workbook....if I select Team 1 in userform I get the 3 charts across the sheet for Team 1...the same for Team 2 and Team 3....Is the layout achievable with small gap between the charts plus the date at the top,labels under each column etc..etc.....

    Thanks

    Terry
    Attached Files Attached Files

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0
    Any thoughts.....

Similar Threads

  1. Change Pivot Table Data Source Using A Drop Down List
    By hanishgautam in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 07-05-2013, 09:33 AM
  2. Replies: 2
    Last Post: 05-26-2013, 03:41 PM
  3. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  4. Replies: 2
    Last Post: 04-26-2013, 04:59 PM
  5. Replies: 8
    Last Post: 04-16-2013, 02:04 PM

Posting Permissions

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