Results 1 to 3 of 3

Relative cell references when creating VBA for Charts

Threaded View

  1. #1
    Registered User
    Join Date
    08-07-2010
    Location
    New York, U.S
    MS-Off Ver
    Excel 2003
    Posts
    3

    Relative cell references when creating VBA for Charts

    I am trying to create individual radar charts for each of the 277 students in my school. My data is set up with each student in a row and three datapoints for each name.

    I am trying to create a macro that will create a chart for each student. I need the column headings to serve as category labels on the chart, so the reference to the labels is fixed, while the data will change for each student.

    Using the Macro Recorder, I have set up the code for a single graph (see below) and then I nested this in a For To loop but can't figure out how to have the chart select the range of data for each student and then have the range change for the next student. See in particular the fourth line from the bottom ("ActiveChart.SetSourceData...")

    1. How do I write the VBA code for the chart to select the student's data? I always want the labels to be in cells A1:E2 (Absolute Reference) but then want the data to be unique for each student (Relative Reference)

    Sub test1()
    '
    ' test1 Macro
    ' Macro recorded 8/25/2010 by bheese
    '
    
    '    
    For Num = 3 to 7
    Range("A1:E2").Select
        ActiveCell.Range("A1:E2,A5:E5").Select
        ActiveCell.Offset(Num, 0).Range("A1").Activate
        Charts.Add
        ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:= _
            "Brand - Radar"
        ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:E2,A5:E5")
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    Next Num
    End Sub
    Any insights would be appreciated
    Attached Files Attached Files
    Last edited by BHcristo; 08-25-2010 at 04:04 PM. Reason: Solved

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