+ Reply to Thread
Results 1 to 2 of 2

Showing Active range for Chart

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-16-2011
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    112

    Showing Active range for Chart

    I am trying to write a Macro to select the active cell from Z$2 and down. I don't want to write a random number at the end since each week I have more or less rows in my table.

    For example

    "='Table'!$Z$2:$Z$5969" should be like "='Table'!$Z$2:$Z but I get an error


    Sub graphtest()
    '
    ' graphtest Macro
    '
    
    '
        Range("A:A,Z:Z,AF:AF,AI:AI,AJ:AJ").Select
        Range("AJ1").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.SetSourceData Source:=Range( _
            "'Table'!$A:$A,'Table'!$Z:$Z,'Table'!$AF:$AF,'Table'!$AI:$AI,'Table'!$AJ:$AJ" _
            )
        ActiveChart.ChartType = xlLine
        ActiveChart.SeriesCollection(1).Values = _
            "='Table'!$Z$2:$Z$5969"
        ActiveChart.SeriesCollection(1).Name = "='Table'!$Z$1"
        ActiveChart.SeriesCollection(2).Values = _
            "='Table'!$AF$2:$AF$5969"
        ActiveChart.SeriesCollection(2).Name = "='Table'!$AF$1"
        ActiveChart.SeriesCollection(3).Values = _
            "='Table'!$AI$2:$AI$5969"
        ActiveChart.SeriesCollection(3).Name = "='Table'!$AI$1"
        ActiveChart.SeriesCollection(4).Values = _
            "='Table'!$AJ$2:$AJ$5969"
        ActiveChart.SeriesCollection(4).Name = "='Table'!$AJ$1"
        ActiveChart.SeriesCollection(4).XValues = _
            "='Table'!$A$2:$A$5969"
        ActiveChart.Location Where:=xlLocationAsNewSheet, Name:= _
            " Graph"
    End Sub
    Last edited by Jerseynjphillypa; 07-30-2012 at 08:27 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,663

    Re: Showing Active range for Chart

    Dim LastRow as Long
    LastRow=Sheets("whatever?").Cells(Rows.Count,"Z").End(xlUp).Row

    ActiveChart.SeriesCollection(1).Values = "='Table'!$Z$2:$Z$" & LastRow
    Ben Van Johnson

+ 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