+ Reply to Thread
Results 1 to 3 of 3

Random text from list IF letter begins with...

  1. #1
    Registered User
    Join Date
    01-03-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    1

    Random text from list IF letter begins with...

    Hi all, hope you're well.

    I've been using the randbetween function to pick a random name from a list (thousands of names in the list).

    I'm looking to take it a step further though.

    For example:

    Return a random name from the list, but only from names in the list that begin with the letter S.

    Would there be a way to use the LEFT or MID functions with RANDBETWEEN to do this?

    So it would essentially find the letter S in the list, and return a random name from the list beginning with S.

    I hope this makes sense?

    Would appreciate any input,

    Thanks
    Steve

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Random text from list IF letter begins with...

    For this to work, your list must be sorted alphabetically in column A. I have written for up to 10000 entries - just don't use the complete column in place of a defined number of rows or it will be reallllly slow

    Array-enter (enter with Ctrl-Shift-Enter)

    =INDEX(A:A,SMALL(IF(LEFT(A1:A10000,1)="S",ROW(A1:A10000)),1)+RANDBETWEEN(0,COUNTIF(A:A,"S*")-1))

    or enter S into a cell - say, B1 - and change the formula (still array-entered) to

    =INDEX(A:A,SMALL(IF(LEFT(A1:A10000,1)=B1,ROW(A1:A10000)),1)+RANDBETWEEN(0,COUNTIF(A:A,B1&"*")-1))
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Random text from list IF letter begins with...

    another option (no sort required) - use simple hepler column (say your names are in Column A, and start from row2 as in Row1 there is a header)
    and if the first letter is in D2 (if not it can be written directly into formula) then in B2 (and copy down):
    =IF(LEFT(A2,1)=$D$2,RAND(),"")

    and selected name For instance in E2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Options:
    if you need more random names (without repetitions) starting with S then =INDEX($A$2:$A$16,MATCH(LARGE($B$2:$B$16,ROW(A1)),$B$2:$B$16,0))
    if there is a chance you will select all use =IFERROR(INDEX($A$2:$A$16,MATCH(LARGE($B$2:$B$16,ROW(A1)),$B$2:$B$16,0)),"_no more names_")
    Attached Files Attached Files
    Best Regards,

    Kaper

+ 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. If Cell Begins with a Letter, Output...
    By Ocean Zhang in forum Excel General
    Replies: 8
    Last Post: 09-28-2022, 08:50 AM
  2. Replies: 30
    Last Post: 06-13-2019, 12:30 PM
  3. Replies: 2
    Last Post: 01-29-2019, 04:41 AM
  4. [SOLVED] Display chosen number if cell text begins with specific letter
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2014, 07:12 AM
  5. [SOLVED] IF number/text in a cell begins with specific letter, then return desired word
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-28-2013, 06:02 AM
  6. [SOLVED] Insert text to cell based on whether the value begins with a letter or number.
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-23-2012, 09:57 AM
  7. Sum only rows where the product begins with letter
    By gruf1968 in forum Excel General
    Replies: 9
    Last Post: 03-07-2010, 04:06 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