parthi2929
New Member
- Joined
- Jun 25, 2011
- Messages
- 3
Hi
I am trying to create a chart object through VBA since my x-axis length is dynamic and I need to calculate the data series dynamically through code.
Before dwelling in to the calculation, I tried first to create a simple chart through VBA. Its just an empty chart and my aim is to have this chart updated for any change done in the inputs (inputs for computation of dataseries) in the worksheet.
The empty chart was created successfully but when I de-focus and activate the macro, the chart is created again. Butif I close the existing chart in worksheet, I need to create a new one (or atleast bring closed one with updated info). How do I do this?? Can any one please provide a sample how to do this?
Below is my unsuccessfull attempt:
Sub Plot_Chart()
'Get the current month and year
currentMonth = DatePart("m", Now)
currentYear = DatePart("yyyy", Now)
'draw a chart
If moneyChart Is Nothing Then
Set moneyChart = Charts.Add
Set moneyChart = moneyChart.Location(Where:=xlLocationAsObject, Name:="Monthly Consumption Analysis Chart 1")
'ElseIf reCreateChart = True Then
' Set moneyChart = Charts.Add
' 'Set moneyChart = ThisWorkbook.Worksheets("Monthly Consumption Analysis").ChartObjects("Monthly Consumption Analysis Chart").Chart
' Set moneyChart = moneyChart.Location(Where:=xlLocationAsObject, Name:="Monthly Consumption Analysis")
' reCreateChart = False
End If
Set mClsEvents = New clsChtEvts1
Set mClsEvents.pCht = moneyChart
MsgBox("Please help")
End Sub
Regards
Parthi2929
I am trying to create a chart object through VBA since my x-axis length is dynamic and I need to calculate the data series dynamically through code.
Before dwelling in to the calculation, I tried first to create a simple chart through VBA. Its just an empty chart and my aim is to have this chart updated for any change done in the inputs (inputs for computation of dataseries) in the worksheet.
The empty chart was created successfully but when I de-focus and activate the macro, the chart is created again. Butif I close the existing chart in worksheet, I need to create a new one (or atleast bring closed one with updated info). How do I do this?? Can any one please provide a sample how to do this?
Below is my unsuccessfull attempt:
Sub Plot_Chart()
'Get the current month and year
currentMonth = DatePart("m", Now)
currentYear = DatePart("yyyy", Now)
'draw a chart
If moneyChart Is Nothing Then
Set moneyChart = Charts.Add
Set moneyChart = moneyChart.Location(Where:=xlLocationAsObject, Name:="Monthly Consumption Analysis Chart 1")
'ElseIf reCreateChart = True Then
' Set moneyChart = Charts.Add
' 'Set moneyChart = ThisWorkbook.Worksheets("Monthly Consumption Analysis").ChartObjects("Monthly Consumption Analysis Chart").Chart
' Set moneyChart = moneyChart.Location(Where:=xlLocationAsObject, Name:="Monthly Consumption Analysis")
' reCreateChart = False
End If
Set mClsEvents = New clsChtEvts1
Set mClsEvents.pCht = moneyChart
MsgBox("Please help")
End Sub
Regards
Parthi2929