+ Reply to Thread
Results 1 to 13 of 13

Randomly select between two dates

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Randomly select between two dates

    Hi Folks,

    In March, 6StringJazzer kindly provided me with a solution for randomly selecting a record when the month within a date matches (See Here)

    However, I've been asked if I can take this one step further and see if it can't be refined between two dates. For example the 'low date' entered in cell B1 and the 'high date' entered in cell C1 ,(I can change the size).

    Then, on activating the macro (through pressing the 'Go' button) it selects a name within (but including) those parameters.

    I've attached the spreadsheet (with Macro) developed by 6StringJazzer. Any help will be greatly appreciated.

    Please don't hesitate to get in touch if you need any further clarity.

    Kindest Regards

    MagicMan
    Attached Files Attached Files

  2. #2
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Randomly select between two dates

    Try

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


    It will give you random names under start to end dates.
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    Thanks Shukla,

    I tried inserting that into my spreadsheet and it didn't work for me. Maybe I'm doing something wrong. I'd be grateful if you could post it in the spreadsheet and upload it so I can see where I may be going wrong.

    MagicMan

  4. #4
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Randomly select between two dates

    May be you have not given dates that is why its happening.

    Check the attached file.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    Sorry Shukla, I'm afraid not.

    When I enter two new dates, it goes completely random and selects from anywhere on the list.

    I thank you for your efforts though

  6. #6
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Randomly select between two dates

    The names will be between those dates which you will give in cell B1 ( Greater than and equal to B1) & C1 (Less than equal to C1) and when you will click on your button it will take random name which you want??

    Am I wrong ????

  7. #7
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    Yip!! That's what I'm after (if the existing macro is causing problems, feel free to delete it).

  8. #8
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Randomly select between two dates

    What do you exactly want can you please speak... as per OP I have given you solution and it is working great...

  9. #9
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    And I do appreciate your efforts shukla.

    I don't know if you have something enabled that I don't, and perhaps should, but when I enter dates in your solution, it doesn't restrict the selection to within those dates. For example, I selected dates between 02/03/17 and 06/03/17 and it returned "Marilyn West"

    Sample 1.png

    However, looking at the list, Marilyn West's entry was made on 30/01/2017

    Sample 2.png

    Whereas it should have been any one of those highlighted in yellow:

    Sample 3.png
    Last edited by MagicMan; 05-11-2017 at 08:23 AM.

  10. #10
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Microsoft® Excel® for Microsoft 365 MSO (Version 2503 Build 16.0.18604.20000) 64-bit
    Posts
    3,992

    Re: Randomly select between two dates

    Sorry my mistake

    try

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


    Now check the attached file.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    A-HA!!

    I've found the problem. You're using the dates in 'List of Names'!A:A, I need to use the dates listed in 'List of Names'!D:D (some of which may be repeated)

  12. #12
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,172

    Re: Randomly select between two dates

    Try this ...

    =INDEX('List of Names'!E:E,SMALL(IF(('List of Names'!D1:D200>=B1)*('List of Names'!D1:D200<=C1),ROW(D1:D200)),
    RANDBETWEEN(1,COUNTIFS('List of Names'!D1:D200,">="&B1,'List of Names'!D1:D200,"<="&C1))))

    Enter with Ctrl+Shift+Enter.

  13. #13
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    447

    Re: Randomly select between two dates

    Phuocam - Many thanks - got there in the end :-)

    Shukla - Thank you for pointing us in the right direction :-)

    Kindest Regards,

    MagicMan

+ 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] Select a name randomly
    By hanif in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2016, 10:19 AM
  2. select numbers randomly
    By kuzna26 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-20-2014, 07:03 PM
  3. VBA to Randomly Select a Cell
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2013, 10:57 AM
  4. Select rows randomly
    By freaksareus in forum Excel General
    Replies: 2
    Last Post: 12-02-2009, 10:04 AM
  5. Code to randomly select
    By fo05kka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2009, 07:22 PM
  6. randomly select value WITHOUT changing
    By Doyle Brunson in forum Excel Formulas & Functions
    Replies: 23
    Last Post: 09-06-2005, 09:05 PM
  7. select names randomly
    By jroque in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 08:40 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