Random Number Game

tommyboy2340

New Member
Joined
Oct 6, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Kind of a random idea, there is this game where you generate a random number between 1 and 100. You then change the range from 1 to (the random number that was generated). This is then repeated until the random number is 1. Is this something that is possible to code? I know how to get a random number from a range but I can not figure out how to replace the max number with the randomly generated number. Any help with this would be amazing!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Are you looking for a formula or a macro? It's easy to do with a formula:

Book1 (version 1).xlsb
A
1Start
2100
354
453
526
626
723
89
97
102
111
12 
13 
14 
15 
Sheet15
Cell Formulas
RangeFormula
A3:A15A3=IF(OR(A2=1,A2=""),"",RANDBETWEEN(1,A2))


Just press F9 for a new game.
 
Upvote 0
Are you looking for a formula or a macro? It's easy to do with a formula:

Book1 (version 1).xlsb
A
1Start
2100
354
453
526
626
723
89
97
102
111
12 
13 
14 
15 
Sheet15
Cell Formulas
RangeFormula
A3:A15A3=IF(OR(A2=1,A2=""),"",RANDBETWEEN(1,A2))


Just press F9 for a new
Wow I didn't think it would be that easy lol. Thank you!
 
Upvote 0
Sure, but that requires VBA. Open a new workbook. Press Alt-F11 to open the VBA editor. Press Alt-IM to Insert a Module. Paste the following code into the window that opens:

VBA Code:
Sub RandomChain()
Dim x As Range
    Set x = Cells(Rows.Count, "A").End(xlUp)
    If x = 1 Then Exit Sub
    x.Offset(1) = WorksheetFunction.RandBetween(1, x)
End Sub

Press Alt-Q to Quit the editor. Press Alt-F8 to open the macro selector. Select RandomChain. Click Options... and put a letter in the hotkey box, such as A. Close the selector box. Now put a number, like 100 in A1. Now every time you press Ctrl-Shift-A, you'll get another row. It'll stop when it hits 1. If you want to play another game, delete all the rows below A1. You can also attach the macro to a button that you can click on, or even put it in the ribbon.

Have fun!
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top