Hi guys,
On the internet (on page tutorialspoint.com) I found the following code for creating charts in vba:
I just tried to see how it works, but I got really confused. What is the ChartObject and how it can recognise where is the chart data in my worksheet.
In this code I don't see anywhere specified which fields we want to use.
Can you please explain how it works or where should I put the cht = Range ("A1:B5") line?
Thank you!
On the internet (on page tutorialspoint.com) I found the following code for creating charts in vba:
Code:
' Procedure to Generate Pie Chart
Private Sub fn_generate_pie_graph_Click()
Dim cht As ChartObject
For Each cht In Worksheets(1).ChartObjects
cht.Chart.Type = xlPie
Next cht
End Sub
' Procedure to Generate Bar Graph
Private Sub fn_Generate_Bar_Graph_Click()
Dim cht As ChartObject
For Each cht In Worksheets(1).ChartObjects
cht.Chart.Type = xlBar
Next cht
End Sub
' Procedure to Generate Column Graph
Private Sub fn_generate_column_graph_Click()
Dim cht As ChartObject
For Each cht In Worksheets(1).ChartObjects
cht.Chart.Type = xlColumn
Next cht
End Sub
I just tried to see how it works, but I got really confused. What is the ChartObject and how it can recognise where is the chart data in my worksheet.
In this code I don't see anywhere specified which fields we want to use.
Can you please explain how it works or where should I put the cht = Range ("A1:B5") line?
Thank you!