+ Reply to Thread
Results 1 to 6 of 6

Macro to calculate Month to year sales based on month selection

  1. #1
    Registered User
    Join Date
    12-14-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    15

    Macro to calculate Month to year sales based on month selection

    Dear friends,

    I am struck in finding solution to write macro to calculate the sales year to month based on month selection. I have attached the data for reference.

    I would like to have the data as following

    1. First I have year drop down where I will select the year ( Apr-Mar series) Ex 2015-16
    2. Second I have month drop down I will select the month Ex Jun-16
    3. Third I have year to date column where i want the sales from Apr-16 to Jun-16 based on my selection of Jun-16

    Regards,
    Chandu
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Macro to calculate Month to year sales based on month selection

    Take a look at the attachment to see if I've got it right. There's a dropdown in E1 to pick the year (Apr-Mar). This dropdown is tied to a dynamic named range on sheet2. You can add more years to the list on sheet2 and the dropdown should adjust automatically. There's a second dropdown in E2 to pick the month. This is tied to a named range on sheet2, as well. The sum is shown in E3 using the formula:

    =SUMIFS($B$2:$B$5000,$A$2:$A$5000,">="&VLOOKUP($E$1,Sheet2!$A$2:$B$13,2,FALSE),$A$2:$A$5000,"<="&EOMONTH(VLOOKUP($E$1,Sheet2!$A$2:$B$13,2,FALSE),0))

    This should calculated the chosen monthly total. It uses the dropdown info to do a lookup on sheet2 for the start date of the range, which is calculated by the following in shee2 B2:

    =IF(A2="","",DATE(IF(MONTH(DATEVALUE(Sheet1!$E$2&" 1"))>=4,2015,2016),MONTH(DATEVALUE(Sheet1!$E$2&" 1")),1))

    It is a bit hard to explain, but the attachment should help to clarify how it works. The formula is currently set up to look at up to 5000 rows of data on sheet1. If you need a bigger range, just change the "5000"s in the formula to something bigger.
    Attached Files Attached Files
    If your problem has been solved, please use "Thread Tools" to mark the thread as "Solved".

    If you're grateful for this site's existence and would like to contribute to the community, please consider posting something hilarious in our joke thread:
    https://www.excelforum.com/the-water...ke-thread.html

  3. #3
    Registered User
    Join Date
    12-14-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro to calculate Month to year sales based on month selection

    Dear Cantosh,

    Thanks for your time. That sheet is working at a extent actually the sales should calculate till that month Year to month sales.

    For ex If I select year as Apr 2015 - Mar 2016 and month as Jun the sales should show 42.6.

    Regards,
    Chandu

  4. #4
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Macro to calculate Month to year sales based on month selection

    Ah! I understand now. Try the new version in the attachment. There are now start and end dates on sheet2, and the Sales formula in E3 is:

    =SUMIFS($B$2:$B$5000,$A$2:$A$5000,">="&VLOOKUP($E$1,Sheet2!$A$2:$B$13,2,FALSE),$A$2:$A$5000,"<="&VLOOKUP($E$1,Sheet2!$A$2:$C$13,3,FALSE))
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-14-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro to calculate Month to year sales based on month selection

    Thanks a lot it worked awesome.

  6. #6
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Macro to calculate Month to year sales based on month selection

    Glad to help, good luck!

+ 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. start month, end month based on year and period
    By stephme55 in forum Excel General
    Replies: 4
    Last Post: 09-06-2016, 04:56 PM
  2. Calculate percentage meeting attendance month by month over the year
    By Carol27 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-20-2016, 02:57 AM
  3. [SOLVED] Calculate nested Product with in a SUMPRODUCT with selection by year and month
    By Gerik in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 11-26-2015, 03:53 PM
  4. Excel VBA Calculate YTD based on month of year
    By prespares in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2015, 06:01 PM
  5. Formula to sum sales over 12 month period not based on calendar year
    By cymraeg in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-02-2014, 12:02 PM
  6. [SOLVED] I have the day and month but not the Year-need a macro to calculate the Year
    By iplayball in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2013, 01:31 AM
  7. [SOLVED] Calculate YTD based on month selection?
    By Aland2929 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-05-2013, 09:29 PM

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