+ Reply to Thread
Results 1 to 2 of 2

VBA to execute random number generation until certain criteria is met

  1. #1
    Registered User
    Join Date
    07-19-2007
    Posts
    51

    VBA to execute random number generation until certain criteria is met

    Hi,
    I am looking to develop a 9 cell grid (3x3) that is populated by random numbers 1 through 9 (where numbers can repeat).
    However upon each execution I want exactly 3 cells to hold the value of "1".

    Examples

    this grid would force a re-run of the random function (not enough 1s)
    2 7 9
    2 1 5
    7 8 6

    also unsuccessful (too many 1s)
    1 6 3
    9 1 1
    1 7 7

    this would be a successful grid
    1 9 2
    1 5 1
    3 4 6

    On a tangential note, if this worksheet were embedded in powerpoint is there a way to execute the VBA script through a PPT action (like a mouse click or create some sort of action button)?
    Last edited by jchambers00; 02-04-2024 at 11:33 AM.

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: VBA to execute random number generation until certain criteria is met

    This macro will create a matrix of 3X3 at Activecell.
    Macro code;
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

+ 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. Random number generation
    By marcb1974 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-03-2023, 09:47 AM
  2. Random Number Generation
    By RalphJ in forum Excel General
    Replies: 1
    Last Post: 06-25-2010, 12:51 PM
  3. [SOLVED] Random number generation
    By Alan Davies in forum Excel General
    Replies: 3
    Last Post: 02-27-2006, 05:40 PM
  4. Random Number Generation
    By MB06 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2006, 04:45 PM
  5. random number generation
    By scotjo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-09-2006, 12:10 PM
  6. random number generation
    By DSpec in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-03-2005, 09:05 AM
  7. Random number generation
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2005, 09:06 AM

Tags for this Thread

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