+ Reply to Thread
Results 1 to 3 of 3

Function inside a button to randomly generate number?

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    London
    MS-Off Ver
    XP
    Posts
    6

    Function inside a button to randomly generate number?

    Hi

    I am trying to put a function into a button.

    The function is

    Please Login or Register  to view this content.
    Then I added an array (spin_range) that cover four cells with values 1, 2, 3, 4.

    Then I added =randomselection(spin_range) which randomly generates either 1, 2, 3 or 4.

    Now I want to add a button to generate this in a cell so I don't have to click into the formula and refresh.

    How do I do this?

    Many thanks
    Last edited by Fotis1991; 09-16-2014 at 05:04 AM. Reason: Pls next time use code tags around your codes as per forum rules.

  2. #2
    Forum Moderator 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: Function inside a button to randomly generate number?

    Hi,

    I don't fully understand your request and why you need a VBA function to do this. Surely the simplest solution is to have
    1. Your range of values in A1:A4,
    2. B1:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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


    Now just link your button to a macro which contains the code
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Function inside a button to randomly generate number?

    I'm struggling in understanding the need for this, too. I assume that fkalinx wants to reuse the generic function.

    fkalinx - you cannot tie a function to a button. You also say that you want this random value to be placed in a cell. Both require a subroutine. So, write a quick subroutine that calls your function and then places that value in the cell of your choice. Assign that macro/subroutine to the button.

    Or, could you just hit the F9 key to recalculate?
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

+ 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. 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
  2. Replies: 0
    Last Post: 11-02-2012, 07:57 PM
  3. VBA Button to generate a number which does not duplicate ~ criteria based
    By opattison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2012, 09:38 AM
  4. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM
  5. 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

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