Macro to create a new chart

K

kimbobo

I've been using this code for a while to easily create a new chart.
However just recently has stopped working. It now created a "default"
excel chart as a new tab in the workbook. Any suggestions?

'********************************************************************
'Creates 2 data series horizontal bar chart
'********************************************************************

Dim myShtName As String
myShtName = ActiveSheet.Name
Charts.Add
ActiveChart.ChartType = xlBarClustered 'Creates Stacked bar
ActiveChart.SetSourceData Source:=Rng, PlotBy:=xlColumns
'References sheet and and cell range of data to generate chart
ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = True

'********************************************************************
'Specifies placement and height & width dimensions of chart
'********************************************************************

With ActiveChart.Parent
.Top = ActiveSheet.Range("F22:Q22").Top
.Left = ActiveSheet.Range("F22:Q52").Left
.Height = ActiveSheet.Range("F22:Q52").Height
.Width = ActiveSheet.Range("F22:Q22").Width
End With
 
N

NickHK

You code works fine for me.
Is the destination (activesheet) sheet protected ?

NickHK
 
K

kimbobo

Hi Nick,

Yeah, the code worked fine about 2 minutes before I used it again. Then
It just suddenly stopped. When I open up the debugger it points to
this:

ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName

Both the sheet and the workbook are unprotected.

Any other ideas? =)

Thanks,

Kim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top