+ Reply to Thread
Results 1 to 3 of 3

Put cell address into a variable

  1. #1
    Registered User
    Join Date
    04-20-2010
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Put cell address into a variable

    I thought this would be a relatively common situation but I can't find any examples anywhere.
    My data is only 2 columns wide. I have a loop that moves down one column finding the largest value. What I also want to do is store the cell addresses (for the active cell and the other to its right) in a variable before it moves on to the next row.
    When the loop is finished I'm looking to use the range variable in the ".SetSourceData Source:=" line when plotting the chart instead of hard coding a range, as the largest value could be anywhere.

    This is the start I've made on the code. The two lines I have no idea about are:
    "Set rng = Range(ActiveCell.Address & ":" & ActiveCell.Offset(0, 1).Address)"
    ".SetSourceData Source:=Sheets("Sheet1").Range(rng), PlotBy:=xlRows"

    Sub AddNewChart()

    Range("I9").Select

    Dim chtChart As Chart
    Dim bigNum As Integer
    Dim rng As Range

    Do Until IsEmpty(ActiveCell)

    If ActiveCell.Value > bigNum Then

    bigNum = ActiveCell.Value

    Set rng = Range(ActiveCell.Address & ":" & ActiveCell.Offset(0, 1).Address)

    End If

    ActiveCell.Offset(1, 0).Select

    Loop

    Set chtChart = Charts.Add
    Set chtChart = chtChart.Location(Where:=xlLocationAsObject, Name:="Sheet1")

    With chtChart
    .ChartType = xlColumnClustered
    .ChartType = xlColumnClustered
    .SetSourceData Source:=Sheets("Sheet1").Range(r1), PlotBy:=xlRows
    .HasTitle = True
    .ChartTitle.Text = "Scores"
    .HasLegend = False

    With .Parent
    .Top = Range("F9").Top
    .Left = Range("F9").Left
    .Name = "MyChart"
    End With

    End With

    End Sub

    This must have been done a million times. Can anyone help me?
    Last edited by pq927; 04-20-2010 at 01:26 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro for a chart

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Put cell address into a variable

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

+ 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