+ Reply to Thread
Results 1 to 2 of 2

VBA to create Graph

Hybrid View

  1. #1
    Registered User
    Join Date
    02-24-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    11

    VBA to create Graph

    I'm trying to write code to add a graph based on data I have in a spreasheet
    Unfortunately the data will sometimes span across 10 cells, but sometimes will will span across 15 or 20 or however many cells (Simply, i will have more data points).

    I tried writing code like this:
        Sheets("Graph").Select
        Columns("A:A").Select
        GRange = Sheets("Graph").Range(Selection, Selection.End(xlToRight)).Select
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLineMarkers
        ActiveChart.SetSourceData Source:=GRange
    But I get a "Object Variable or With block Variable Not Set" error on the 3rd line..

    Any thoughts?

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: VBA to create Graph

    You must use Set statement for GRange variable:
    Set GRange = Sheets("Graph").Range(Selection, Selection.End(xlToRight))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1