using a macro to edit the data range of a chart

  • Thread starter Monkey-See, Monkey-Do
  • Start date
M

Monkey-See, Monkey-Do

Does anyone know how to write a macro in order to select the data range of a
chart?

The reason is that I have a macro which inserts a line and then copies data
into that new line from another worksheet. Doing this adjusts the data range
of the chart which already exists in the worksheet and means that the new
line is ignored....

I tried to record a macro to do this but it falls over after clicking select
data.
 
J

Joel

Sub getchartrange()

'get chart name
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
chrtname = shp.Name
MsgBox ("Chart Name = " & chrtname)
Exit For
End If
Next shp
Set chrt = ActiveSheet.ChartObjects(chrtname)
chrt.Activate
ActiveChart.SetSourceData _
Source:=Sheets("Sheet1").Range("A1:B3"), _
PlotBy:=xlRows

End Sub
 

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