VBA Chart title from multiple cells

Human_doing

Board Regular
Joined
Feb 16, 2011
Messages
137
Hi all,

The following code creates a simple chart using VBA:

Code:
Sub Chart()
    Range("H1:I13").Select
    Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Sheets("Sales").Range("H1:I13"), PlotBy:= _
        xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sales"
End With
End Sub

I have the name of the department (sales) as the name of the worksheet and also in cell A2. The date of the current period is in cell A3 (Apr 10 - Mar 11). I am looking for the title of the chart to be 'Sales data Apr 10 - Mar 11' i.e. cell A2 + 'Sales data' + Cell A3, can anyone please help with the VBA for this?

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
In sheet module.
Code:
Sub F()

    Dim cht As Chart
    
    Set cht = Me.ChartObjects(1).Chart
    
    With cht
        .SetElement msoElementChartTitleAboveChart
        .ChartTitle.Characters.Text = Me.Range("A2") & " Sales data " & Me.Range("A3")
    End With

End Sub
 
Last edited:
Upvote 0
Sorry, you have a chart sheet. Here's fix:
Code:
Sub F()

    With Charts("Chart1")
        .SetElement msoElementChartTitleAboveChart
        .ChartTitle.Characters.Text = Range("A2") & " Sales data " & Range("A3")
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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