updating data location to build a VBA graph

A

alvis

hello,

I am trying to build this simple macro where i can hit a keystroke and
graph whatever cells i have selected. The problem is that the macro
only graphs only from a fixed range and i want to be able to graph any
data i select.

here is the macro:

Sub graph()
'
' graph Macro
'
'
' Keyboard Shortcut: Ctrl+Shift+G
'
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),
PlotBy:= _
xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
With Selection.Interior
.ColorIndex = 15
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
With Selection.Border
.Weight = 2
.LineStyle = 0
End With
Selection.Interior.ColorIndex = xlAutomatic
Sheets("Sheet1").DrawingObjects("Chart 1").RoundedCorners = False
Sheets("Sheet1").DrawingObjects("Chart 1").Shadow = False
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlThick
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
Selection.Delete
End Sub


so graphs only data from C5:K5 and i want to be able to graph any data
i select...
thanks,
alvis
 
G

Guest

possibly change

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),

to

ActiveChart.SetSourceData Source:=Selection
 
A

alvis

i tried that but doesn't work,
thanks though
Tom said:
possibly change

ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),

to

ActiveChart.SetSourceData Source:=Selection
 

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