+ Reply to Thread
Results 1 to 16 of 16

RandBetween without Blanks

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    RandBetween without Blanks

    Hi,

    I Have a row of numbers with blanks in & i need to create a random number between 7 & 18, but i cant have a blank or a zero, it must only be one of the numbers in the row.

    7 8 9 10 11 13 14 15 17 18


    Obviously =RANDBETWEEN(7,18) wont work & i have tried Macro's but they seem to crash Excel


    If you can help that would be great.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: RandBetween without Blanks

    If you set up your data in the first column, try:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    Hi, thanks but i cant really get this to work, it only puts 1 number in cell "A1" & i need the random numbers to be un a Row elsewhere in the sheet, not at the beginning?

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: RandBetween without Blanks

    If your list of allowed numbers in A1:A10, then INDEX($A$1:$A$10,RANDBETWEEN(1,10)) should return a random value from the range.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: RandBetween without Blanks

    If you numbers are in B2:Z2 try
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: RandBetween without Blanks

    Please try

    =Choose(RandBetween(1,10), 7, 8, 9, 10, 11, 13, 14, 15, 17, 18)

    Regards.

  7. #7
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    thanks for the reply but as there are blanks between the numbers in the row, it still brings up blanks

  8. #8
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    thanks but this still shows blanks where there are spaces between the numers

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: RandBetween without Blanks

    No idea who you are talking to, but did you try my suggestion, it ignores the blank cells.

  10. #10
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    thanks however as the numbers change quite often & as there are many rows it would be too time consuming to keep updating all the formulars all the time

  11. #11
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    Hi Fluff, yes i tried your formula but it it still brings up a blank sometimes

  12. #12
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    Hi Fluff, you are right, however the rows of numbers i have are generated by formulas or links to other cells, so your formula shows up #NUM, when there is a blank in a cell, however if i type the numbers in manually (which is impractical) then your formula works

  13. #13
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: RandBetween without Blanks

    We might need a sample file to see exactly what kind of set up you have and how the blanks are figuring into this and all.

    As a guess, this worked:

    1) If my numbers intermingled with blanks are in A1:Z1.
    2) Will there always be 10 real numbers to choose from, or do you need to determine how many numbers there are at run time (a COUNT() function should work, if at run time). For now, I am assuming there will always be 10. Replace with something else if necessary.
    3) Add a helper row below that assigns an integer to each number. Something like =IF(A1="","",1) in A2. In B2, =IF(B1="","",MAX($A2:A2)+1) copy/paste/fill into C2:Z2
    4) Extract a random number:
    4a) RANDBETWEEN() to get a random integer between 1 and 10 (or COUNT(A1:Z1)) RANDBETWEEN(1,10)
    4b) a MATCH() function to find that integer in row 2 MATCH(RANDBETWEEN(...),A2:Z2,0)
    4c) an INDEX() function to extract the corresponding number from row 1: =INDEX(A1:Z1,MATCH(...))

    Are we getting closer?

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: RandBetween without Blanks

    If you won't always have 13 numbers in the row, try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Fluff13; 01-27-2022 at 09:09 AM.

  15. #15
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: RandBetween without Blanks

    Hi Fluff, i think that i can close this out with your solution, thanks again

  16. #16
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: RandBetween without Blanks

    Glad to help & thanks for the feedback.

+ 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. Randbetween to exclude 3 or more other randbetween with Sudoku rules
    By Mayday67 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-22-2021, 01:59 PM
  2. [SOLVED] Multiple Conditions based on blanks/non-blanks and dates
    By clari55a in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 10-01-2021, 10:31 AM
  3. Replies: 1
    Last Post: 08-06-2019, 10:43 PM
  4. BLANKS (Not Really Blanks) AND Rearrange ignoring blanks
    By shivspatil in forum Excel General
    Replies: 4
    Last Post: 02-02-2018, 08:28 AM
  5. [SOLVED] Access Query shows (Blanks) but no blanks in data!
    By MissDB in forum Access Tables & Databases
    Replies: 0
    Last Post: 09-08-2016, 07:16 AM
  6. Replies: 10
    Last Post: 07-03-2015, 04:29 PM
  7. [SOLVED] Paste Special Skip Blanks not skipping blanks, but overwriting...
    By gsrosin in forum Excel General
    Replies: 0
    Last Post: 02-22-2005, 12: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