Consulting

Results 1 to 5 of 5

Thread: Solved: Create chart based on current month

  1. #1
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location

    Solved: Create chart based on current month

    Hello,

    I am a newbie to VBA and i've been trying to figure out how to update a graph based on the current month and then looking back six months in total. No luck!

    I've attached a spreadhsheet to show what I'm trying to do. Basically, every month the spreadsheet will bring in data from another spreadsheet, and i would like the chart to update, but only by taking into account the past 6 months of data.

    Please can anyone show me how I would do this using VBA?

    Many thanks,

    Aminul
    Last edited by aminul; 08-31-2010 at 05:47 AM.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Please have another go at posting the workbook? Click on Go Advanced, scroll down to "Manage Attachments" and follow the prompts from there.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location
    Thanks aussiebear. I've attached the file.

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    I've created some dynamic range names for the data source and the source of the x-axis labels. The range for "High" for example, as been defined as

    =OFFSET(Sheet1!$A$2,MATCH(TODAY(),Sheet1!$A$3:$A$28,TRUE)-5,1,6,1)
    • The OFFSET function allows you to create dynamic ranges that vary either the starting point, or the count of rows and/or columns.
    • Our starting point for defining the range is cell A2 on Sheet1.
    • The MATCH function searches for the closest date to today and returns the index number of the relevant cell. In this example it would return 11, which is the cell for September 2010.
    • After MATCH gives a result of 11, we subtract 5. Basically this tells Excel that the starting row for the range is 5 rows above the current month.
    • 1 tells Excel that the column for this range starts 1 cell to the right of our starting point of A2.
    • 6 sets the total number of rows in our range.
    • 1 sets the total number of columns in our range.
    I've changed the chart so that the data source for each series now uses these range names. The ranges will dynamically shift each month without you having to change anything.

    We are what we repeatedly do. Excellence, therefore, is not an act but a habit.
    Aristotle

  5. #5
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    3
    Location
    that works brilliantly! thank you very much geek girl lau!

Posting Permissions

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