Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Create Charts with a Macro

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is it possible to create charts with a macro? I have sets of "x" and "y" data on over 100 worksheets and I'd like to quickly make an x-y scatter plot for every single worksheet.

    Also, i dont know if it makes a difference, but the number of points is not the same on every worksheet.

    Thanks!

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    It is possible to add charts using VBA. (and very difficult to mess about with if you record a macro to see what the code is.)

    To embed a scatter chart on Sheet1 and use B2:C11 as the source data, you would use code like this:


    Dim Cht As Chart

    Set Cht = Application.Charts.Add
    With Cht
    .ChartType = xlXYScatter
    .SetSourceData Source:=Sheets("Sheet1").Range("B2:C11"), PlotBy:=xlColumns
    .Location Where:=xlLocationAsObject, Name:="Sheet1"
    End With



  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Mark,

    Thanks alot. This is what I am looking for.

    Do you (or does anyone) know how I can change the following two parts:

    - How can I make it refer to x and y values that are in non-adjacent columns? (for the "Range" part)

    - Is there a way to make it dynamically plot however many points there are (for example, some sheets have 10 points, some have 20, some have hundreds... they are all in the same columns just on different sheets).

    Please let me know if this is unclear. Thank you all


Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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