+ Reply to Thread
Results 1 to 4 of 4

How to create user defined RANDBETWEEN function in Excel using VBA

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

    How to create user defined RANDBETWEEN function in Excel using VBA

    Hello All,

    I want to create custom RANDBETWEEN function to stop excel from recalculating with every click. I want to make it work for this formula.

    =IF(NOT(ISBLANK(B3)),RANDBETWEEN(15,1506009),"")

    Please help. Thanks

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,566

    Re: How to create user defined RANDBETWEEN function in Excel using VBA

    It seems like a simple UDF, so I am not sure what part of coding the UDF you would need help with. It seems like it should be as simple as
    Please Login or Register  to view this content.
    Called as =MyRandbetween(15,1506009) or nested inside of your IF() function just like the built in function =IF(NOT(ISBLANK(B3)),MyRANDBETWEEN(15,1506009),"")

    There may be some question about when you do and don't want it to recalculate. As a UDF, it will recalculate the random number whenever Excel decides to calculate that cell. Nested inside of your IF() function, that will mean that anytime B3 ends up in the "to be calculated" list, this cell will be recalculated. So anytime B3 changes, or the cells B3 depends on are changed. It will also recalculate whenever a full recalculation is performed (like at file open). You may want to test it in many different scenarios so you can see if it is working the way you want.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: How to create user defined RANDBETWEEN function in Excel using VBA

    Try...
    Please Login or Register  to view this content.
    Or use Application.RandBetween()
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

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

    Re: How to create user defined RANDBETWEEN function in Excel using VBA

    Thank you all it worked.

+ 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. [SOLVED] VBA - How to create a user defined function?
    By TheN in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-19-2016, 07:38 PM
  2. Replies: 1
    Last Post: 07-19-2014, 06:29 AM
  3. Help to create a user defined function with IF and AND
    By Elomaldo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2014, 11:00 AM
  4. Use formula to create a User Defined Function
    By lindomsm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2013, 06:54 AM
  5. How do I create a user-defined function in Excel 2011?
    By dpbsmith in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2012, 06:26 PM
  6. VBA/Excel - how do I create a user-defined function out of a makro?
    By marasmussen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2007, 08:21 PM
  7. [SOLVED] How can I create a user defined function in excel?
    By Martinj in forum Excel General
    Replies: 4
    Last Post: 08-20-2005, 02:05 PM

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