VBA code: automatic chart title for graph with 2 different series (cluster column, line)

candor345

New Member
Joined
Dec 27, 2010
Messages
24
How do I automatically pull a chart title (from a data table on another sheet) and make it appear on a graph that has both cluster columns and a line?

Initially, when I only had a cluster column, the chart title showed up automatically. Now, after adding the line as a second X series the chart title disappears. I want to add in a code so that the chart title still shows up.

The code is a bit complex:
1. the data table has about 80 rows of independent variables (in sheet called "DataTable")
2. If the user wants to see a graph for the independent variable, then there is a "1" denoting "yes" (in the DataTable sheet, shown in red text here)
3. The code then graphs an individual cluster-line graph for each variable (on the "Graphs" sheet).
4. Finally, I need help: how do I change this code so that the chart title shows up for each graph? (the chart title is already in "DataTable" -- column O and the row of the independent variable called "CurRow" here). Near the bottom I have red text for the Chart formatting.

Appreciate your help, thanks

Code:
Dim CurRow As Integer
    Dim TableRow As Integer, TableNum As Integer
    Dim RowIncrement As Integer
    Dim TableColumn As Integer
    
   Sheets("DataTable").Select
    CurRow = 42
    ChartNum = 1
'    TotalCharts = Range("N129").Value
    TableRow = 21
    RowIncrement = 24
    TableColumn = 7
    
    While (Range("N" & CurRow) <> "")
        If ([COLOR="Red"]Range("N" & CurRow) = 1[/COLOR]) Then [COLOR="Red"]'selects variables[/COLOR]
            Sheets("Graphs").Select
            
             Range("'DataTable'!$AN" & CurRow).Copy
            
            Range("G" & LTrim(Str(TableRow + 2))).Select
             Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Range("G" & LTrim(Str(TableRow + 2)) & ":AD" & LTrim(Str(TableRow + 2))).Select
            Application.CutCopyMode = False
            Selection.FillRight
            
            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.SetSourceData Source:=Range("'DataTable'!$O$" & CurRow & ":$AM$" & CurRow)
            ActiveChart.ChartType = xlColumnClustered
            ActiveChart.Parent.Left = 50
            ActiveChart.Parent.Top = 400 + 300 * (ChartNum - 1)
            
            ActiveChart.PlotBy = xlColumns
            ActiveChart.PlotBy = xlRows
              ActiveChart.SetElement (msoElementLegendNone)
            ActiveChart.SeriesCollection(1).XValues = "='DataTable'!$P$41:$AM$41"
 
            Range("G" & LTrim(Str(TableRow + 2)) & ":AD" & LTrim(Str(TableRow + 2))).Copy
            [COLOR="red"]ActiveChart.Paste
            ActiveChart.PlotArea.Select
            ActiveChart.SeriesCollection(2).Select
            ActiveChart.SeriesCollection(2).ChartType = xlLine[/COLOR]
         
         With ActiveChart
                .HasTitle = True
                [COLOR="red"].ChartTitle.Text = "='DataTable'!$O$ & CurRow"[/COLOR] '[COLOR="red"]Title source is the Data table but chart titles do not appear  [/COLOR]
            End With
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top