ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro for graphing - should be very easy... (https://www.excelbanter.com/excel-programming/371128-macro-graphing-should-very-easy.html)

[email protected]

macro for graphing - should be very easy...
 
hello,

i am trying to set up a keyboard shortcut where i can select some
cells, hit the shortcut and a graph would be build based on the
selected data. so far i can do that but i can only graph data from the
recorded range when i start the macro B4:J4 - i want to be able to
graph from any dataset i select...

Sub graph()
' Keyboard Shortcut: Ctrl+Shift+G
'
Range("B4:J4").Select
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B4:J4")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
End Sub

thanks,


PCLIVE

macro for graphing - should be very easy...
 
Try something like this:

Sub graph()
' Keyboard Shortcut: Ctrl+Shift+G
'
ws = ActiveSheet.Name
sl = Selection.Address
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets(ws).Range(sl)
ActiveChart.Location Whe=xlLocationAsObject, Name:=ws
End Sub

HTH,
Paul


wrote in message
ups.com...
hello,

i am trying to set up a keyboard shortcut where i can select some
cells, hit the shortcut and a graph would be build based on the
selected data. so far i can do that but i can only graph data from the
recorded range when i start the macro B4:J4 - i want to be able to
graph from any dataset i select...

Sub graph()
' Keyboard Shortcut: Ctrl+Shift+G
'
Range("B4:J4").Select
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B4:J4")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
End Sub

thanks,





All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com