Macro to randomly choose numbers

GeeBDee

New Member
Joined
Dec 7, 2015
Messages
36
Hi

I would like to click on a button to have a macro run and choose any amount of random numbers between 1 - 10. So click the button and it may choose 3 random numbers between 1 - 10, click it again and it may choose 5 random numbers, then click and it chooses 9 random numbers and so on.

I would like to know if there is anyway a macro is capable of this and if so, please advise the code?

Or am I asking too much?

If this is not possible then a macro to just choose 1 random number between 1 - 10 please.

Grant
 
you know what ?

i guess i can do it; maybe. so stay tuned for an update.

well, if two days passed and you did not see any update; know that my brain went into freeze mode. only by then, open a new topic and ask the question and hope that it will summon an Excel god to solve it.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi G,

Google this for a starter.
Displaying Images based on a Result

Done with a formula that refers to numbers for the pic of choice. The numbers could be the random one your code produces.

If you get hung up, then a new thread with what you have been able to do so far may be a way to go.

Hoard
 
Upvote 0
I think Howard is right.

this is do-able with formulas; i tried expanding the macro i gave you copy paste images into positions based on the random number generated but i failed.

the formula workaround is as follows:

first paste the list of image you have into a new sheet, keep in mind that you resize the images and the cells you place the images on accordingly :

6t4eCSB.png



notice that next to each image i put an index based on the image reference (the random numbers that will appear in their destination at sheet1)

next in sheet1, under each cell designated for the random numbers to appear (beneath row 7); place an image link their, do not worry about the links for now just paste any image link.

now for each image link you have to create a dynamic range that refers to the right number image at sheet 2 see the name manager formulas below

(to be continued)
 
Upvote 0
Code:
Slot1=OFFSET(Sheet2!$B$2,Sheet1!$C$7-1,1)
Slot2=OFFSET(Sheet2!$B$2,Sheet1!$D$7-1,1)
Slot3=OFFSET(Sheet2!$B$2,Sheet1!$E$7-1,1)
Slot4=OFFSET(Sheet2!$B$2,Sheet1!$F$7-1,1)
Slot5=OFFSET(Sheet2!$B$2,Sheet1!$G$7-1,1)
Slot6=OFFSET(Sheet2!$B$2,Sheet1!$H$7-1,1)
Slot7=OFFSET(Sheet2!$B$2,Sheet1!$I$7-1,1)
Slot8=OFFSET(Sheet2!$B$2,Sheet1!$J$7-1,1)
Slot9=OFFSET(Sheet2!$B$2,Sheet1!$K$7-1,1)
Slot10=OFFSET(Sheet2!$B$2,Sheet1!$L$7-1,1)

6ubqx8X.png


after defining the dynamic ranges go to each PicLink click on it, go to the formula bar and type the name of the corresponding dynamic range:

i.e. = Slot1 and so on....


and now you will have this final result :

6tRwMFb.png




this will work with what ever range of random numbers you select to appear on the sheet (up to 10)


do not forget give me a like and a virtual beer.

i cannot send the file for you as this is against the forums rules and my inbox is blocked as the Gurus of this forum have put me in Jail :)

but i guess if you followed the steps i mentioned and did some googling you will be able to make it happen.


cheers; may the force be with you(y)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,873
Messages
6,127,454
Members
449,383
Latest member
DonnaRisso

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