Hi Everyone
i found this template online and was using it perfectly until i updated to 2013. Can anyone help me modify the code so it works with 2013.
Cheers
Option Explicit
Sub CallAB()
ActiveSheet.ChartObjects.Delete
ActiveSheet.Shapes.AddChart
AssignBubbleSource ActiveSheet.ChartObjects(1), ActiveSheet.Range("A1:D5")
End Sub
Private Sub AssignBubbleSource(chtBblChart As ChartObject, rngChartSource As Range, Optional blnHeader As Boolean = True)
Dim lngRow As Integer
Dim lngIndex As Byte
Dim wksSourceSheet As Worksheet
Const NameColumn As Integer = 0 'Change this value to change Name Column number
Const FirstColumn As Integer = 1 'Change this value to change column number of X Values
Const SecondColumn As Integer = 2 'Change this value to change column number of Y Values
Const ThirdColumn As Integer = 3 'Change this value to change column number of Z Values
Set wksSourceSheet = rngChartSource.Parent
With chtBblChart.Chart
.ChartType = xlBubble3DEffect
End With
For lngIndex = 1 To chtBblChart.Chart.SeriesCollection.Count
chtBblChart.Chart.SeriesCollection(1).Delete
Next lngIndex
lngIndex = 1
For lngRow = rngChartSource.Row + Abs(blnHeader) To rngChartSource.Row + rngChartSource.Rows.Count - 1
If wksSourceSheet.Cells(lngRow, rngChartSource.Column) = "" Then
GoTo AddNextItem
Else
With chtBblChart.Chart
.SeriesCollection.NewSeries
With .SeriesCollection(lngIndex)
.XValues = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + FirstColumn)
.Values = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + SecondColumn)
.BubbleSizes = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + ThirdColumn)
.Name = wksSourceSheet.Cells(lngRow, rngChartSource.Column + NameColumn).Value '"='" & strSourceShtName & "'!R" & lngRow & "C" & (rngChartSource.Column + NameColumn)
End With
End With
End If
lngIndex = lngIndex + 1
AddNextItem:
Next lngRow
With chtBblChart.Chart
.ChartType = xlBubble3DEffect
.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
.SetElement (msoElementPrimaryValueAxisTitleRotated)
.SetElement (msoElementDataLabelRight)
.Axes(1, 1).AxisTitle.Text = rngChartSource.Cells(1, rngChartSource.Column + FirstColumn).Value
.Axes(2, 1).AxisTitle.Text = rngChartSource.Cells(1, rngChartSource.Column + SecondColumn).Value
End If
End With
lngRow = Empty
lngIndex = Empty
Set wksSourceSheet = Nothing
End Sub
i found this template online and was using it perfectly until i updated to 2013. Can anyone help me modify the code so it works with 2013.
Cheers
Option Explicit
Sub CallAB()
ActiveSheet.ChartObjects.Delete
ActiveSheet.Shapes.AddChart
AssignBubbleSource ActiveSheet.ChartObjects(1), ActiveSheet.Range("A1:D5")
End Sub
Private Sub AssignBubbleSource(chtBblChart As ChartObject, rngChartSource As Range, Optional blnHeader As Boolean = True)
Dim lngRow As Integer
Dim lngIndex As Byte
Dim wksSourceSheet As Worksheet
Const NameColumn As Integer = 0 'Change this value to change Name Column number
Const FirstColumn As Integer = 1 'Change this value to change column number of X Values
Const SecondColumn As Integer = 2 'Change this value to change column number of Y Values
Const ThirdColumn As Integer = 3 'Change this value to change column number of Z Values
Set wksSourceSheet = rngChartSource.Parent
With chtBblChart.Chart
.ChartType = xlBubble3DEffect
End With
For lngIndex = 1 To chtBblChart.Chart.SeriesCollection.Count
chtBblChart.Chart.SeriesCollection(1).Delete
Next lngIndex
lngIndex = 1
For lngRow = rngChartSource.Row + Abs(blnHeader) To rngChartSource.Row + rngChartSource.Rows.Count - 1
If wksSourceSheet.Cells(lngRow, rngChartSource.Column) = "" Then
GoTo AddNextItem
Else
With chtBblChart.Chart
.SeriesCollection.NewSeries
With .SeriesCollection(lngIndex)
.XValues = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + FirstColumn)
.Values = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + SecondColumn)
.BubbleSizes = "='" & wksSourceSheet.Name & "'!R" & lngRow & "C" & (rngChartSource.Column + ThirdColumn)
.Name = wksSourceSheet.Cells(lngRow, rngChartSource.Column + NameColumn).Value '"='" & strSourceShtName & "'!R" & lngRow & "C" & (rngChartSource.Column + NameColumn)
End With
End With
End If
lngIndex = lngIndex + 1
AddNextItem:
Next lngRow
With chtBblChart.Chart
.ChartType = xlBubble3DEffect
.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
.SetElement (msoElementPrimaryValueAxisTitleRotated)
.SetElement (msoElementDataLabelRight)
.Axes(1, 1).AxisTitle.Text = rngChartSource.Cells(1, rngChartSource.Column + FirstColumn).Value
.Axes(2, 1).AxisTitle.Text = rngChartSource.Cells(1, rngChartSource.Column + SecondColumn).Value
End If
End With
lngRow = Empty
lngIndex = Empty
Set wksSourceSheet = Nothing
End Sub