Creating VBA code to create random number and highlight cell result

Cquake

Board Regular
Joined
Dec 12, 2017
Messages
60
Office Version
  1. 2016
Platform
  1. Windows
I am looking for some help to create the correct VBA code to use with my ActiveX Button to generate a random number between 1-24 ( These numbers will be in cells H4:H28) that would then highlight the corrosponding cell (using a light red background with bold black numbers) in the matching random number data result generated in cells I4:I28. Can this be done as I have looked around but have not found the answer to this. Any help would be appreciated.

Thanks
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello,

Before getting to VBA ... make sure to clarify your objective ...

Generating a random number could be done with

Code:
[COLOR=#2C2C2D][FONT=PT Serif]=RANDBETWEEN(1,24) [/FONT][/COLOR]

But your text suggest you would need in fact 24 numbers (between 1 and 24) randomly distributed ... with NO DUPLICATES ...

The issue of highlighting any cell ... can always be taken of ... afterwards ...

Thanks for clarifying ... :wink:
 
Last edited:
Upvote 0
I'm not clear on the requirement. Could you post a sample set of data and results and explain again in relation to that sample?
 
Upvote 0
Hello,

Before getting to VBA ... make sure to clarify your objective ...

Generating a random number could be done with

Code:
[COLOR=#2C2C2D][FONT=PT Serif]=RANDBETWEEN(1,24) [/FONT][/COLOR]

But your text suggest you would need in fact 24 numbers (between 1 and 24) randomly distributed ... with NO DUPLICATES ...

The issue of highlighting any cell ... can always be taken of ... afterwards ...

Thanks for clarifying ... :wink:

Thanks for replying. I found the solution to my problem and now realize I was trying to make this more diffulcult than what it was. Thanks again for looking at it.
 
Upvote 0
Glad you could fix your problem ...:wink:

Cheers
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,147
Members
452,615
Latest member
bogeys2birdies

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