Consulting

Results 1 to 3 of 3

Thread: Solved: Source and location function

  1. #1

    Solved: Source and location function

    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.

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

    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 ...

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim rng As Range
    Set rng = Selection
    Charts.Add
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=rng
    ActiveChart.Location Where:=xlLocationAsObject, Name:=rng.Parent.Name
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    This is exactly what i needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •