Macro to select cells in a range randomly without repeating?

musicgold

Board Regular
Joined
Jan 9, 2008
Messages
197
Hi,

I have a range of 100 cells consisting of numbers, arranged in a 10x10 format. I need to randomly choose one cell and remove the number in it from the pool. I have to keep repeating the process until all 100 numbers have been selected. In other words, I can't select a cell twice and the pool shrinks after each selection.

How can I create a macro to do this process in the most efficient manner?

Thanks
 
Here is another macro that you can consider which works with any size grid (just change the A1:J10 in the Set statement) and it works with any content in the cells as well....
VBA Code:
    Rng.Find("?*", Cells(Int(Rng.Rows.Count * Rnd + Rng(1).Row), Int(Rng.Columns.Count * Rnd + Rng(1).Column)), , xlWhole, , , , , False).Select

Thanks. I see that you are choosing a random starting point for the find method.
However I am not sure what you are doing with Rng(1).Row and Rng(1).Column in the line above. In fact, I am not sure what happens when you pass an integer to a range object.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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