PaulExcelVBA
New Member
- Joined
- Mar 30, 2015
- Messages
- 5
Hello everyone, I will explain what I need to do and what is happening, the code will be after the explanations.
What I am trying to do:
I have a small database with the average consumption of every month, it is basically two lines, one with the 12 months, along with the 12 payments.
Everytime I click my custom button, I would like it to generate a new chart containning the info OR it could be the same chart (as long as it keeps the updated info), it could be only hidden and show up when the button is pressed.
It doesn't need to be deleted, but it needs to keep the same visual pattern.
However, this chart needs to be "deleted" or hidden after it is seem.
What is happening:
After I click the button, a series of mistakes happen, it does generate the chart, but it informs the error ('-2147024809 (80070057)') and it shows the chart, but it doesn't make all the necessary visual adjustments.
I think one of the main issues is that everytime it creates a chart, it changes the name (such as chart 15, 16, 17, etc) since it is a new chart.
How can I fix this or proceed?
Thank you!
What I am trying to do:
I have a small database with the average consumption of every month, it is basically two lines, one with the 12 months, along with the 12 payments.
Everytime I click my custom button, I would like it to generate a new chart containning the info OR it could be the same chart (as long as it keeps the updated info), it could be only hidden and show up when the button is pressed.
It doesn't need to be deleted, but it needs to keep the same visual pattern.
However, this chart needs to be "deleted" or hidden after it is seem.
What is happening:
After I click the button, a series of mistakes happen, it does generate the chart, but it informs the error ('-2147024809 (80070057)') and it shows the chart, but it doesn't make all the necessary visual adjustments.
I think one of the main issues is that everytime it creates a chart, it changes the name (such as chart 15, 16, 17, etc) since it is a new chart.
Code:
Sub ChartTest()
'
' ChartTest Macro
'
'
Range("A8:L9").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("'Relatório CPFL'!$A$8:$L$9")
ActiveChart.Legend.Select
Selection.Delete
ActiveSheet.ChartObjects("Gráfico 18").Activate
ActiveChart.SeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.75
.Transparency = 0
.Solid
End With
ActiveChart.ChartArea.Select
With ActiveSheet.Shapes("Gráfico 18").Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.25
End With
With ActiveSheet.Shapes("Gráfico 18").Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.8999999762
.Transparency = 0
End With
ActiveSheet.Shapes("Gráfico 18").Title = ""
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = "Consumo Mensal"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Consumo Mensal"
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 7).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(8, 7).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
End Sub
How can I fix this or proceed?
Thank you!