+ Reply to Thread
Results 1 to 10 of 10

Sum Qty based on two date range

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    India
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2307 Build 16.0.16626.20170) 64-bit
    Posts
    14

    Sum Qty based on two date range

    Hi Experts,

    I have dates in the format dd-mmm-yyyy in Column "E" and Qty (Nos) in Column "F". In user form, I have 2 text boxes ("Start" and "End" Date) and on inputting dates in text boxes,I need the sum of qty to be calculated with respect to all date range in "E" and the Sum Qty in a msgbox.

  2. #2
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Sum Qty based on two date range

    Could you attach a sample workbook with desensitized data? I'm wondering if
    1) all your dates are in that format
    2) if they have to be in that format instead of an excel-recognized date format?

  3. #3
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Sum Qty based on two date range

    If they are all in that format you could try something like this (I used input boxes, you will have to edit that to use your userform)
    Please Login or Register  to view this content.
    Edit: you're also going to have to change the loop starting values to "2" if you have titles in columns "E" and "F" instead of the data starting at row 1
    Last edited by danielexcelvba; 07-26-2017 at 04:00 PM.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sum Qty based on two date range

    This ought to work... but convert the textboxes to actual dates to be safe... dates in excel can get messy:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 07-26-2017 at 04:44 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Sum Qty based on two date range

    Well that's 1000x easier. Didn't know you could recognize dates in that format.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sum Qty based on two date range

    @daniel, yes, you should be able to.... I am assuming the cells are formatted as a date in that format? I always try to work with date variables rather than strings but if i HAVE to have a string, i paste it in the dd-mmm-yyyy format so that excel can't mistake the month for the day and vice-versa.

  7. #7
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Sum Qty based on two date range

    I read it as dd-mm-yyyy (which is not a recognized format)
    Even then your code would work though!

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sum Qty based on two date range

    True... As long as cells are formatted as a date and the date variable in VBA is set correctly, the code should be fine.
    CDate could still get confused with a textbox though, if the textbox has a dd-mm-yy entry or mm-dd-yy (all depending on the system date settings).
    I always use a custom calendar form I have, that allows me to force the user to pick a date, and that will update a textbox with the dd-mmm-yyyy format. Or give the user specific day month and year textboxes and use dateserial.
    Last edited by Arkadi; 07-26-2017 at 04:41 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    07-10-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2013
    Posts
    430

    Re: Sum Qty based on two date range

    Yeah I just figured it was formatted as text since dd-mm-yyyy would get screwed up if it was set to date.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Sum Qty based on two date range

    daniel, in cell formatting if you pick custom format, you can specify dd-mm-yyyy... and that would still be formatted as an actual date. You are correct, it is not an option in the "Date" settings, but will still be seen as a date by Excel.

+ 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: 1
    Last Post: 11-24-2015, 03:00 AM
  2. Check a date range and return value based on the date range
    By KeithCar in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2015, 12:55 PM
  3. Highlight Rows Based on Date Range Using Static Date and Current Date
    By SaraStravers in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-23-2015, 07:38 PM
  4. Replies: 5
    Last Post: 01-05-2015, 03:57 PM
  5. VBA to enter date range based on date range in above cell
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2013, 08:45 AM
  6. [SOLVED] Date Filter based on Cell Input - single date or range of dates
    By babaloo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2012, 10:32 AM
  7. copy date based on date -refer to date range
    By mindpeace in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2006, 08:35 AM

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