+ Reply to Thread
Results 1 to 11 of 11

How to generate fixed length of data (randomly)

  1. #1
    Registered User
    Join Date
    04-27-2016
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    15

    How to generate fixed length of data (randomly)

    Hello,

    I'm trying to generate random set of numbers using the data that's already there in the Excel sheet.
    Is there a simple formula that would enable me to achieve this ?

    The data from A2 to A30 is to be randomly generated again on a new column.

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,720

    Re: How to generate fixed length of data (randomly)

    What are your expected results??? Just a random order of the data in A2 to A30?

    =INDEX($A$2:$A$30,RANDBETWEEN(1,29))

  3. #3
    Registered User
    Join Date
    04-27-2016
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    15

    Re: How to generate fixed length of data (randomly)

    Awesome John, this works !

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,720

    Re: How to generate fixed length of data (randomly)

    If you have the answer to your problem, please mark thread as solved ("Thread Tools" at top of first post)

    Thank you for the feedback.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to generate fixed length of data (randomly)

    One way would be to fill B2:B30 with =RAND() functions then sort columns A:B using column B as the key.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How to generate fixed length of data (randomly)

    Quote Originally Posted by JohnTopley View Post
    =INDEX($A$2:$A$30,RANDBETWEEN(1,29))
    In case you don't know how many cells is in the range:

    =INDEX(A$2:A$30,RANDBETWEEN(1,ROWS(A$2:A$30)))

    Note that if you're copying that formula down a column it's possible (probable) that you could get duplicates.
    Last edited by Tony Valko; 04-29-2016 at 08:43 AM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

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

    Re: How to generate fixed length of data (randomly)

    As usual little modified Tony's formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    edit:
    I think modification above was wrong

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

    assume col A:A has no more numbers than declared
    It works but every refresh formula checking full A:A column so this is theory only but not for "fast" use .
    Last edited by sandy666; 04-29-2016 at 11:16 AM.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to generate fixed length of data (randomly)

    Quote Originally Posted by sandy666 View Post
    As usual little modified Tony's formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    You may find #REF values cropping up since the last match can return the value 30, there being 30 values in column A including the label in A1. Change it to

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


    Did you also pick up on Tony's comment that you will almost certainly get duplicates. Whether that's what you want only you can say.

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

    Re: How to generate fixed length of data (randomly)

    It was because of "In case you don't know how many cells is in the range".
    and Yes I got Tony's comment

  10. #10
    Registered User
    Join Date
    04-27-2016
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    15

    Re: How to generate fixed length of data (randomly)

    Hi All,

    thanks so much for keeping this thread active. Many thanks to all of your help. It works!

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: How to generate fixed length of data (randomly)

    You're welcome. We appreciate 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. Replies: 10
    Last Post: 11-21-2015, 12:06 PM
  2. Have Word randomly generate numbers.
    By atomichybrid in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2015, 05:55 AM
  3. [SOLVED] Macro to Selectively Import Fixed Length Data into Excel
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2014, 12:06 AM
  4. Simple macro to randomly generate 0 or 1
    By mattdaviddesign in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2013, 08:32 PM
  5. Center data in a fixed length text field
    By indullg83 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2009, 01:18 PM
  6. [SOLVED] Generate column of 1's and 0's randomly
    By Ian Engelbrecht in forum Excel General
    Replies: 6
    Last Post: 04-01-2006, 09:52 AM
  7. Save data in a worksheet in fixed length fields...
    By dietzd in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 03:06 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