+ Reply to Thread
Results 1 to 17 of 17

Need to search within date range within formula.

  1. #1
    Registered User
    Join Date
    11-24-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    7

    Need to search within date range within formula.

    Apologies for the day 1 spam of questions...

    I've just had a formula fixed for me on here but I've run into another problem; I've realised I need to apply the condition between a range of dates rather than doing greater or less than, otherwise every date after the due date will have the cost applied even if it isn't an annual one. So what I'm looking for is something like:
    =if('site1!'B2=DateValue("01/09/2023-31/09/2024"),'site1!'V2,0'). I'm assuming I need to use something other than an equals sign to indicate the range or not a dash between the start and end dates, but I'm note sure what.

    UK Date Formatting is applied, if that helps.

  2. #2
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365
    Posts
    3,187

    Re: Need to search within date range within formula.

    Hi,
    I dont think there is a function in excel that will do 'between' range (unlike SQL)
    you will have to use >=, <= to indicate the range.

    something like that:
    if(and('site1!'B2>=DATE(2023,9,1),'site1!'B2<=DATE(2024,9,31)),'site1!'V2,0')

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    Try like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Note that September only has 30 days. EOMONTH saves you having to work it out (or remember it)
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    11-24-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Need to search within date range within formula.

    It's coming up with a red dotted band around the formula box now. Current layout:

    =IF('Site1!U2>=date(1/9/2023)<=DATE(31/8/2024),(Site1!V2,0). If I put a comma between the two date ranges it thinks the second one is the 'if true' function.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    Using DATE as opposed to DATEVALUE is probably a better option. There can be no doubt about year, month and day which is a possibility in Regional variations.

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Need to search within date range within formula.

    I don't know what are you trying to achieve in your formula but

    dateanddatevalue.png

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    You have a single quote in front of the first Site.

    If a sheet name has spaces in it, you need single quotes around it. If it doesn't, you don't. So, Site!U2 or 'This Site'!U2
    Last edited by TMS; 11-25-2022 at 07:20 AM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    And you are missing the AND.

    Go with one of the options given … noting the difference in format between DATE and DATEVALUE as Sandy has pointed out. Not forgetting how many days there are in each month … I see you have changed from September to August; was that intentional?

  9. #9
    Registered User
    Join Date
    11-24-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Need to search within date range within formula.

    Okay, had a crack with both. Still getting the red line. I'm assuming I've missed out something I just can't see. Current working below:

    =if(AND('Site1'!U2>=DATE("01/09/2023"),'Site1'!U2<=EOMONTH(DATE("31/08/2024"),0)),'Site1'!V2,0)

    When I click on the site 1 up to the date I get the 'logical one' highlight, the second site 2 gets 'logical 2', clicking on the 'eomonth' brings up the date highlight, but after that it's as though the other two functions aren't recognised as being part of the same formula.

    Yes I changed to August - apologies, the range I'm looking to apply runs between the beginning of our year to end (1st September - 31st August).

    Edit: Forgot to add - I'm using 'Site 1' right now to maintain the anonymity of where I'm working but eventually this will be changed to the site name which has spaces in it.
    Last edited by Intermedi; 11-25-2022 at 07:24 AM.

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Need to search within date range within formula.

    You didn't read post#6

    Quote Originally Posted by Intermedi View Post
    =if(AND('Site1'!U2>=DATE("01/09/2023"),'Site1'!U2<=EOMONTH(DATE("31/08/2024"),0)),'Site1'!V2,0)

  11. #11
    Registered User
    Join Date
    11-24-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Need to search within date range within formula.

    Hi Sandy - my formatting is UK rather than US so I'm using the 'DATE' function as day, month, year. Is DATEVALUE better for this? I got a bit confused as I don't have 'text'.

  12. #12
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Need to search within date range within formula.

    function DATE using year, month, day doesn't matter where you are
    DATE cannot use text date

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    @Intermedi: please pay attention to the detail

  14. #14
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Need to search within date range within formula.

    try

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    AND contains 0 so it will always be FALSE

  15. #15
    Registered User
    Join Date
    11-24-2022
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    7

    Re: Need to search within date range within formula.

    I've got it working (curiously with a date/month/year format!), thank you both for your help, and your patience!

  16. #16
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Need to search within date range within formula.

    You are welcome

    Excel has some rules and sometimes it's worth following them
    if you have problem with functions use

    funsarg.png

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Need to search within date range within formula.

    Either of these should do what you want.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The first is, perhaps, easier to read although Regional differences may confuse day/month with month/day.

    The second is shorter and is a fixed format … year, month, day … wherever you are in the world.




    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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. [SOLVED] Formula to search by contract number and between date range
    By jharvey87 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-21-2017, 04:36 PM
  2. [SOLVED] Formula help - search fixed table for corresponding date range
    By phildosaurus in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-26-2016, 10:49 AM
  3. Search large date range with narrow filetered range
    By druth in forum Excel General
    Replies: 14
    Last Post: 08-02-2014, 09:01 AM
  4. [SOLVED] formula to search text from another sheet and add the sum based on a date range
    By Billyngu in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 02-10-2014, 11:57 PM
  5. Search date range +/- 7 days and return date that falls within range
    By tlafferty in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-13-2013, 03:26 PM
  6. [SOLVED] Don't understand & sign for date range search in formula, is this correct?
    By boo1952 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-14-2012, 12:24 PM
  7. Formula to search for today's date and return range of data
    By paramore in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2012, 02:17 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