modify code to suit 2013

Keewi82

New Member
Joined
Jun 29, 2016
Messages
9
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
What is it NOT doing correctly ??
If there is an error, which line gives the error ??
To do this use F8 to step through the code manually until you get an error line ( highlighted in yellow)

Can you please post using code tags in future....see my sig block
 
Upvote 0
Thanks for the reply Michael

when i run the macro in 2013 an error 400 appears!

When i use the F8 function it appears to be this line ActiveSheet.ChartObjects.Delete
 
Upvote 0
Try skipping the error

Code:
Sub CallAB()
On Error Resume Next
ActiveSheet.ChartObjects.Delete
ActiveSheet.Shapes.AddChart
AssignBubbleSource ActiveSheet.ChartObjects(1), ActiveSheet.Range("A1:D5")

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,614
Messages
6,125,848
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top