VBA Help: Making a chart from selected data

Noobachu

New Member
Joined
Jun 28, 2011
Messages
7
I'm having some trouble, and if someone would be so kind as to help, I'd be incredibly grateful.
I'm trying to make charts from data that I have selected in a worksheet, using a macro (since I will end up making a few hundred of these). This is in Excel 07, by the way. Using the "Record Macro" feature, I came up with:

Sub Graph()
'
' Graph Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Frequency'!$I$4:$I$13")
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SeriesCollection(1).XValues = "='Frequency'!$A$4:$A$13"
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.Legend.Select
Selection.Delete
End Sub

I need to change the source, but I don't know how; the source of the graph needs to be whatever I have selected at the time, not the range I4:I13. However, the Xvalues need to always be A4:A13, as they are here.
How do I make it graph what I have selected on the chart?

Thanks,

A Noob
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I'd imagine that it'd be something like this:
Code:
Sub Graph()
'
' Graph Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
stradd = "'" & ActiveSheet.Name & "'!" & Selection.Address
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(stradd)
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SeriesCollection(1).XValues = "='Frequency'!$A$4:$A$13"
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.Legend.Select
Selection.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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