+ Reply to Thread
Results 1 to 18 of 18

Find a date and its row number in a column of dates

  1. #1
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Find a date and its row number in a column of dates

    I have dates sorted in ascending order in a column. I want to find a date and its absolute row number for two different cases.

    Case 1 (Formula 1 & Formula 2): I want to find the first date (and its row number) that is equal to a given date or the next available date if it does not exist

    Case 2 (Formula 3 & Formula 4): I want to find the last date (and its row number) that is equal to a given date or the last previous date if it does not exist.

    For example, I have a column with dates:
    row1: 8/1
    row2: 8/2
    row3: 8/2
    row4: 8/4
    row5: 8/4
    row6: 8/5
    row7: 8/7


    Case 1:
    Given Date= 8/3 => Excel should find 8/4 and row4 (show results in 2 different cells)
    Given Date= 8/4 => Excel should find 8/4 and row4 (show results in 2 different cells)

    Case 2:
    Given Date= 8/3 => Excel should find 8/2 and row3 (show results in 2 different cells)
    Given Date= 8/4 => Excel should find 8/4 and row5 (show results in 2 different cells)

    Thank you so much in advance!

    p.s.
    Case 1 is used as the start date of a calculation
    Case 2 is used as the end date of a calculation
    Last edited by viking2; 08-04-2018 at 10:24 PM.

  2. #2
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    I figured out Case 2:
    (assuming the given date is in cell C2, and dates are in A1:A7):

    To find the Column (Formula 4):
    =MATCH(C2,A1:A7,1)

    To find the Date (Formula 3):
    =INDEX(A1:A7,MATCH(C2,A1:A7,1))

    However, I cannot figure out Case 1

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,053

    Re: Find a date and its row number in a column of dates

    Is this a homework assignment?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    Quote Originally Posted by FDibbins View Post
    Is this a homework assignment?
    Not at all. I have been trying to figure this out for a few days now. I need the row numbers (and dates) to perform some other calculations.

    p.s. What made you believe that it was a homework assignment?

  5. #5
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    I have uploaded a workbook with my Case 2 formulas. However, I can't figure out the Case 1 formulas to use in Cells F16 and G16.

    p.s. I have subscribed to this post. However, I am not notified by E-mail when there is a response. I am also not notifed about private messages (I have confirmed the E-mail and it is not going to Spam)
    Attached Files Attached Files
    Last edited by viking2; 08-05-2018 at 02:45 AM. Reason: Corrected a small error in the workbook

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    There are some issues for some people with subscriptions - apologies for that. The tech team are aware.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    Try this:

    =MIN(LOOKUP(2,1/($A$2:$A$8<=A17),ROW($A$2:$A$8)),IFNA(MATCH(A17,$A$2:$A$8,0),99^99))

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    Why have you removed the workbook you provided???

    I am attaching it here with my solution added for the benefit of everyone reading this thread.

    EDIT: Please don't post-edit workbooks! If you have made a mistake, add an amended workbook in a new post to the thread.
    Attached Files Attached Files
    Last edited by AliGW; 08-05-2018 at 02:56 AM.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    Amended for the new file:

    =MIN(LOOKUP(2,1/($A$1:$A$7<=A16),ROW($A$1:$A$7))+1,IFNA(MATCH(A16,$A$1:$A$7,0),99^99))

    Some response to my attempts to help you would be appreciated!

  10. #10
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    Quote Originally Posted by AliGW View Post
    Try this:

    =MIN(LOOKUP(2,1/($A$2:$A$8<=A17),ROW($A$2:$A$8)),IFNA(MATCH(A17,$A$2:$A$8,0),99^99))
    Thank you for the quick response!

    I am sorry, but I uploaded an incorrect workbook that had the dates in A2:A8 instead of A1:A7 as originally posted. I have uploaded the correct workbook now.

    In any case, I tried your formula in the workbook with the dates in A2:A8 (like you seemed to have used in your response), and placed your formula in Cell F17, but I get an error: #NAME?

    p.s. I am using Excel 2010

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    I've given a formula for the new workbook above. Sorry - I did not spot Excel 2010. Give me a moment to amend again.

  12. #12
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    Quote Originally Posted by AliGW View Post
    Amended for the new file:

    =MIN(LOOKUP(2,1/($A$1:$A$7<=A16),ROW($A$1:$A$7))+1,IFNA(MATCH(A16,$A$1:$A$7,0),99^99))

    Some response to my attempts to help you would be appreciated!
    Tried it again with the new formula in the workbook with dates in A1:A7 (and Formula in Cell F16). However, same error.

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    Try this:

    =MIN(LOOKUP(2,1/($A$1:$A$7<=A16),ROW($A$1:$A$7))+1,IFERROR(MATCH(A16,$A$1:$A$7,0),99^99))

    In future, please don't post-edit posts and attachments - as has been proved here, it just leads to confusion. Correct mistakes simply by adding a new post to the thread. Thanks.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

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

  15. #15
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    Thanks for the new formula! It works in the workbook that I uploaded, with Dates in A1:A7.
    However, it strangely doesn't work when the dates are in A3:A9 (my simpler Case 2 Formulas work in either case).

    I have attached two workbooks with your formula and the dates in either A1:A7 or A3:A9.

    How do I modify your formula to work for a different range of dates other than A1:A7, e.g. A3:A9 (in addition to, of course, changing the range from A1:A7 to A3:A9 in the formula)?

    p.s. I have changed the wording from "row" to "position" as everything is in relation to the position in the array (which is needed for the INDEX function to work)
    Attached Files Attached Files
    Last edited by AliGW; 08-05-2018 at 06:40 AM. Reason: Unnecessary quotation removed.

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    Try this:

    =MIN(LOOKUP(2,1/($A$3:$A$9<=A18),ROW($A$1:$A$9))+1,IFERROR(MATCH(A18,$A$3:$A$9,0),99^99))

    The bit in red is where you went wrong. This needs to start at A1 to give the position in the array that you want.

    If this is now what you want, please mark the thread as solved.

  17. #17
    Registered User
    Join Date
    08-15-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Find a date and its row number in a column of dates

    Quote Originally Posted by AliGW View Post
    Try this:

    =MIN(LOOKUP(2,1/($A$3:$A$9<=A18),ROW($A$1:$A$9))+1,IFERROR(MATCH(A18,$A$3:$A$9,0),99^99))

    The bit in red is where you went wrong. This needs to start at A1 to give the position in the array that you want.

    If this is now what you want, please mark the thread as solved.
    Thank you so much for your help AliGW!
    It is amazing what you can do with some [self-taught] Excel knowledge! I will need to spend some time trying to figure out how your formula works .

    One final comment in case someone else later reads this. The formulas used calculates the position in the array rather than the absolute row number.
    The array position is needed for the Index function to work (The Index function finds the date from the position).

    I also wanted to find the absolute row number. It was found by adding
    Please Login or Register  to view this content.
    to the end of the two formulas.
    I have attached the final example in case someone needs something similar in the future.

    I will mark this as solved (but get back to it later if need be).
    Attached Files Attached Files

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,338

    Re: Find a date and its row number in a column of dates

    If you are still puzzling over it tomorrow and want me to explain, just holler (I think that’s what you Americans say).

    Yes, most of what I know has been learnt since joining this forum.

+ 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. Need to find the number of dates between two repair dates with condition
    By prirosmail in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-18-2018, 04:05 PM
  2. Replies: 5
    Last Post: 01-16-2014, 11:51 AM
  3. [SOLVED] Find first date of the month in range and return column number
    By jben86 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2013, 08:30 PM
  4. Replies: 4
    Last Post: 02-11-2011, 08:59 AM
  5. Replies: 3
    Last Post: 08-11-2009, 11:46 AM
  6. Replies: 8
    Last Post: 02-27-2009, 06:06 PM
  7. [SOLVED] Find a "date" in a column of dates in Excel 2000
    By JR Hester in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-02-2005, 06:20 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