+ Reply to Thread
Results 1 to 4 of 4

Generating and returning a random number to a cell by clicking a Button

  1. #1
    Registered User
    Join Date
    08-27-2021
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    2

    Generating and returning a random number to a cell by clicking a Button

    Hi,

    I am new to excel VBA and Macros. I am trying to create a click button to automatically generate a random number (1000,9999) to "F5" cell in my worksheet. I have created the form Button used record macros to record the steps using the RAND(1000,9999) function typed into F5 after I click the button.

    This is the code I am running:

    Please Login or Register  to view this content.
    When I click the button I am getting VBA compile error: "invalid outside procedure". I read that this error is to do with declaring variables but I am not sure if this is the case here.
    Any help is appreciated. Thanks.

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Generating and returning a random number to a cell by clicking a Button

    Hi aea1022 & welcome to the forum

    Try below code ...
    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Registered User
    Join Date
    08-27-2021
    Location
    Australia
    MS-Off Ver
    2017
    Posts
    2

    Re: Generating and returning a random number to a cell by clicking a Button

    Thanks nankw83,

    Your solution works perfectly.

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,713

    Re: Generating and returning a random number to a cell by clicking a Button

    Glad to help & thanks for the added Rep+

    Please take a moment & mark this thread as [SOLVED] from the Thread Tools above your first 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. [SOLVED] Random number generator not always generating random numbers
    By Murman01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2021, 05:29 PM
  2. [SOLVED] Generating a random number
    By kimi01 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-02-2020, 11:57 AM
  3. [SOLVED] Generating Random Numbers
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2012, 10:29 AM
  4. generating random number & 0s and 1s
    By nynamyna in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-22-2011, 05:01 PM
  5. Random number generating
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-14-2010, 03:39 PM
  6. Generating a Random Number of Random Numbers
    By Garrus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2010, 09:39 AM
  7. Random Number Generating
    By tctees in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2008, 12:55 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