Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do i build a stacked bar graph with three variables? | Charts and Charting in Excel | |||
I need to build a graph Chart | Charts and Charting in Excel | |||
link not updating after changing source location | Excel Discussion (Misc queries) | |||
RefEdit updating Current Cell location | Excel Programming | |||
Updating calculations + graph when i enter in new data WITHOUT OFF | Excel Worksheet Functions |