+ Reply to Thread
Results 1 to 3 of 3

VBA Chart Last Row select last 12 rows

  1. #1
    Registered User
    Join Date
    01-19-2019
    Location
    Portland, Oregon
    MS-Off Ver
    2010
    Posts
    6

    VBA Chart Last Row select last 12 rows

    Hi everyone,

    I looked everywhere to find out how to do this in VBA. Any help would be appreciated.

    Basically in summary I have a VBA UserForm that populates a chart and puts it in an image frame. I set the range of dates from A2 until the end of the column | for example Range("A2", Range("A2").End(xlUp)) |. This works great for a complete graph of ALL the dates of the values. Now I want to be able to show only the last 12 days as the whole range goes back a couple of years. What I am trying to figure out is how to only select the last 12 Dates and Values, using this Range method to first find the end of the column and then select that cell plus the 11 before it (Up).

    Here is an example:

    A
    Date
    29 Dec 20
    30 Dec 20
    31 Dec 20
    01 Jan 21
    02 Jan 21
    03 Jan 21
    04 Jan 21
    05 Jan 21
    06 Jan 21
    07 Jan 21
    08 Jan 21
    09 Jan 21
    10 Jan 21
    11 Jan 21
    12 Jan 21
    13 Jan 21
    14 Jan 21
    15 Jan 21
    16 Jan 21
    17 Jan 21
    18 Jan 21
    19 Jan 21
    20 Jan 21
    21 Jan 21


    So, is there a way where I can simply do something like "Range("A2",Range("A2").End(xlUp) - 12"

    Please help, thanks!

    Phil

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,770

    Re: VBA Chart Last Row select last 12 rows

    You mean something like below?
    Please Login or Register  to view this content.
    “Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.”
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    01-19-2019
    Location
    Portland, Oregon
    MS-Off Ver
    2010
    Posts
    6

    Re: VBA Chart Last Row select last 12 rows

    CK76,

    Thanks! I figured out another workaround: Range(Cellls(Rows.Count,1).End(xlDown).Offset(-11,0), Cells(Rows.Count,1).End(xlDown))

    But yours was exactly what I wanted and a lot cleaner. Thanks.

    Phil

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 11
    Last Post: 04-19-2021, 07:46 PM
  2. [SOLVED] Select last row in column A and select 49 rows up, copy results to A2
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2016, 02:59 PM
  3. Creating a Chart from select columns/rows in a Pivot Table
    By dreamer001 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-23-2015, 03:04 PM
  4. [SOLVED] Switching columns and rows in select data in chart
    By jh51745 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2013, 06:44 AM
  5. [SOLVED] Switching columns and rows in select data in chart
    By jh51745 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-03-2013, 08:42 AM
  6. Code to prevent user to Select COLUMNS but allow to select ROWS
    By tengrosita in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2011, 03:46 AM
  7. Replies: 1
    Last Post: 04-23-2007, 04:23 PM

Tags for this Thread

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