+ Reply to Thread
Results 1 to 6 of 6

Macro to generate a random number between 2 specific values into specific cells.

  1. #1
    Registered User
    Join Date
    04-09-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    10

    Macro to generate a random number between 2 specific values into specific cells.

    Hello everyone,

    I've lurked here for a while and it's helped me quite a bit in the past, but now I find myself stumped on what is probably the "easiest" macro I've put together.

    Essentially what I'm trying to do is make a button, that when pressed, generates a random number between 81 and 103 in cells B34:37 that I can press over and over to my heart's content.

    I don't have the add-in that allows me to use the formula "=RANDBETWEEN()" or elst I'd just use that, and I've tried to google this and came up with nothing. I found various tid-bits of code here and there, but I couldn't fit it together to do what I wanted it to.

    Thanks in advance for the help.
    Last edited by Nerfmagnet; 04-10-2013 at 11:42 AM. Reason: Solved

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro to generate a random number between 2 specific values into specific cells.

    Please Login or Register  to view this content.
    This should do it.
    Last edited by 111StepsAhead; 04-10-2013 at 11:39 AM. Reason: Made the code shorter.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Macro to generate a random number between 2 specific values into specific cells.

    Hello and welcome to the forum,

    Randbetween is both available in Excel versions 2003 and up. I don't know why you're not seeing it.

    Luckily there is already a workaround ready on Chip Pearson's site. I have tweaked it and works fine on my computer:

    Please Login or Register  to view this content.
    The short version would be:

    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 04-10-2013 at 11:36 AM.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    04-09-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    10

    Re: Macro to generate a random number between 2 specific values into specific cells.

    Please Login or Register  to view this content.
    I made a very small tweak to it to get it to fit where I wanted, and it works wonderfully! Thank you so much.

    Is there anywhere you could point me to learn a little more about VBA? I'll mark the thread solved. Thanks again for the help, and sorry if it was too easy a fix.

  5. #5
    Registered User
    Join Date
    04-09-2013
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    10

    Re: Macro to generate a random number between 2 specific values into specific cells.

    Thanks for the input abousetta. Steps ahead beat you to the punch it appears though. I've copied your answers down as well in case I need to change the format up in the future. I've rep'd you both and marked the thread as solved.

    Many many thanks.

  6. #6
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Macro to generate a random number between 2 specific values into specific cells.

    Hi Nerfmagnet,

    Abousetta links to a website that can teach you a lot about VBA. I've found the best way to learn though is start a project and Google what you need to do. There are many existing examples of code and once you use and understand that code you will remember it for the future. If you are looking for a good book I'd suggest Excel 2007 Power Programming with VBA by John Walkenbach. When I first started out with VBA I read through that book and learned a very large amount of things about VBA. It's also a good reference to use so I keep it close.

    Best of luck.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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