PDA

View Full Version : Solved: Source and location function



enfantter
08-12-2008, 02:21 AM
Hi all,

Im currently trying to set up a wizard which will make layout of graphs as i want them instead of the excel standard. The macro itself is working fine, but i have some problem in the begining. My thought is that first the user chooses the selection -> creates graph -> put in active sheet.

Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B343")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"


so my question is
1) What is the code i need to put for source to be selection (instead of this static range)
2) What code can i put for "where:" and/or "source:" to get the graph placed in the active sheet - the same as where the selection is made (here sheet1)

Hope that anybody can help ...

xld
08-12-2008, 03:14 AM
Dim rng As Range
Set rng = Selection
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=rng
ActiveChart.Location Where:=xlLocationAsObject, Name:=rng.Parent.Name

enfantter
08-12-2008, 03:29 AM
This is exactly what i needed!