Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i build a stacked bar graph with three variables? claryal Charts and Charting in Excel 3 April 14th 23 05:32 PM
I need to build a graph Chart Lonsomdov Charts and Charting in Excel 6 February 13th 08 09:31 PM
link not updating after changing source location Fred Excel Discussion (Misc queries) 0 October 11th 07 06:05 PM
RefEdit updating Current Cell location coco Excel Programming 1 August 6th 05 07:53 PM
Updating calculations + graph when i enter in new data WITHOUT OFF superman Excel Worksheet Functions 0 February 2nd 05 05:05 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"