+ Reply to Thread
Results 1 to 8 of 8

Generate Random Numbers when values detected under other columns

  1. #1
    Registered User
    Join Date
    01-03-2019
    Location
    FortMcmurray, Alberta
    MS-Off Ver
    Office 2016
    Posts
    9

    Generate Random Numbers when values detected under other columns

    Hello All,

    Can someone help me in generating auto random numbers (thorugh VBA or nesting functions) under Column A when values are populated under column B & Column C. Please find the screenshot attached for your reference, we want to generate auto numbers for Column A2.

    Capture 1.JPG

    Thanks,
    Abbat

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Generate Random Numbers when values detected under other columns

    .
    Paste this in A2 : =IF(NOT(ISBLANK(B2)),RAND()*1000000,"")

  3. #3
    Registered User
    Join Date
    01-03-2019
    Location
    FortMcmurray, Alberta
    MS-Off Ver
    Office 2016
    Posts
    9

    Re: Generate Random Numbers when values detected under other columns

    Thanks but everytime, i generate the new number i.e. A3 then A2 changes, if I generate A4 then A3 & A2 changes. It would be a great help if i can only generate positive integer only without changing the previously generated number.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Generate Random Numbers when values detected under other columns

    .
    This method will require a Command Button on the sheet to activate the following macro.
    Also, you will need to select the blank cell in Col A where you want the random number prior to clicking the button.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-03-2019
    Location
    FortMcmurray, Alberta
    MS-Off Ver
    Office 2016
    Posts
    9

    Re: Generate Random Numbers when values detected under other columns

    Thanks for your response but I like your previous solution better.

    I am utilizing following function to randomly generate positive integer =IF(NOT(ISBLANK(B2)),RANDBETWEEN(15,1506009),"").

    The recalculation issue can be solved through the following VBA code for RAND() numbers but can you help me in making it for RANDBETWEEN numbers since its not working properly.

    Please Login or Register  to view this content.
    Capture_RAND VBA Code.JPG

    Thanks

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,446

    Re: Generate Random Numbers when values detected under other columns

    .
    There are two ways you can prevent the random numbers from changing when you enter ANOTHER random number or data somewhere in the sheet.

    # 1:

    Go to Excel Options / Formulas / Calculation Options .. then change the setting to : Manual

    # 2:

    You can assign one cell in the sheet to accept the random number. A cell that won't be utilized for anything else.
    Then you can copy the VALUE of that cell to the cell in Col A where you want the random number to reside. Since
    the cell in Col A doesn't have the RANDOM formula but ony the random number value, it will not change when you enter
    data elsewhere.

    Otherwise, you will need to use the macro approach.

  7. #7
    Registered User
    Join Date
    01-03-2019
    Location
    FortMcmurray, Alberta
    MS-Off Ver
    Office 2016
    Posts
    9

    Re: Generate Random Numbers when values detected under other columns

    #1: the formulas dont work if we change the setting to manual.

    #2: then we cannot automate the random number creation through user forms which is the end objective.

    While if we can define our own RANDBETWEEN function which works as equivalent to function defined in excel, it will stop it from recalculating.

    Thanks again for all the help.

  8. #8
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Generate Random Numbers when values detected under other columns

    Not sure what you want
    But try this
    Please Login or Register  to view this content.
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

+ 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. Generate random numbers between two values to a total
    By halshehab in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-16-2015, 12:37 AM
  2. [SOLVED] generate random numbers between 1 to 10 vba rnd()
    By ihrktho in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-09-2014, 09:51 AM
  3. Generate Random Numbers Between 0-9
    By dreicer_Jarr in forum Excel General
    Replies: 11
    Last Post: 01-17-2014, 01:00 AM
  4. [SOLVED] Generate Random numbers where sum = 1
    By sajeel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-18-2013, 07:12 AM
  5. [SOLVED] Generate Random Numbers
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2013, 02:49 AM
  6. generate random numbers
    By fo05kka in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-08-2009, 09:55 PM
  7. Generate random numbers between two values and with a given mean
    By pinosan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2005, 10: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