ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   updating data location to build a VBA graph (https://www.excelbanter.com/excel-programming/370659-updating-data-location-build-vba-graph.html)

[email protected]

updating data location to build a VBA graph
 
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 Whe=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


Tom Ogilvy

updating data location to build a VBA graph
 
possibly change

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

to

ActiveChart.SetSourceData Source:=Selection

--
Regards,
Tom Ogilvy


" wrote:

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 Whe=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



[email protected]

updating data location to build a VBA graph
 
i tried that but doesn't work,
thanks though
Tom Ogilvy wrote:
possibly change

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

to

ActiveChart.SetSourceData Source:=Selection

--
Regards,
Tom Ogilvy


" wrote:

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 Whe=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





All times are GMT +1. The time now is 10:03 AM.

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