Hello I'm new in VBA and currently trying to make a bubble plot in EXCEL 2016 with VBA but every time I run the macros it gives me back System "Error &H80070057 (-2147024809)". The code I'm using is:
Sub graphic2()
ActiveSheet.Shapes.AddChart2(269, xlBubble).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""dots"""
ActiveChart.FullSeriesCollection(1).XValues = "=Aux2!$B2:$B10001"
ActiveChart.FullSeriesCollection(1).Values = "=Aux2!$C2:$C10001"
ActiveChart.FullSeriesCollection(1).BubbleSizes = "=Aux2!$D2:$D10001"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""clusters"""
ActiveChart.FullSeriesCollection(2).XValues = "=Aux2!$G2:$G501"
ActiveChart.FullSeriesCollection(2).Values = "=Aux2!$H2:$H501"
ActiveChart.FullSeriesCollection(2).BubbleSizes = "=Aux2!$I2:$I501"
ActiveChart.SetElement (msoElementDataLabelCenter)
ActiveChart.SetElement (msoElementDataLabelNone)
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.ChartTitle.Text = "Clusters calculados"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Clusters calculied"
With Selection.Format.TextFrame2.TextRange.Characters(1, 20).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(10, 10).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(20, 1).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
End Sub
Can anyone explain me what the problem might be?
Sub graphic2()
ActiveSheet.Shapes.AddChart2(269, xlBubble).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""dots"""
ActiveChart.FullSeriesCollection(1).XValues = "=Aux2!$B2:$B10001"
ActiveChart.FullSeriesCollection(1).Values = "=Aux2!$C2:$C10001"
ActiveChart.FullSeriesCollection(1).BubbleSizes = "=Aux2!$D2:$D10001"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""clusters"""
ActiveChart.FullSeriesCollection(2).XValues = "=Aux2!$G2:$G501"
ActiveChart.FullSeriesCollection(2).Values = "=Aux2!$H2:$H501"
ActiveChart.FullSeriesCollection(2).BubbleSizes = "=Aux2!$I2:$I501"
ActiveChart.SetElement (msoElementDataLabelCenter)
ActiveChart.SetElement (msoElementDataLabelNone)
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.ChartTitle.Text = "Clusters calculados"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Clusters calculied"
With Selection.Format.TextFrame2.TextRange.Characters(1, 20).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(10, 10).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(20, 1).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
End Sub
Can anyone explain me what the problem might be?