Random Userform backcolor between 2 color

sinanvarann

New Member
Joined
Dec 3, 2020
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
Hey guys when i click the button i want to see randomly 2 color on userform backcolor.
I could do only for one color. Like this;
grey=rgb(153,153,153)
userform1.backcolor=round(grey,0)
This 2 row gives me 1 color but i need randomly 2 color.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you need totally random background colors, try:
VBA Code:
Private Sub UserForm_Initialize()
    Me.BackColor = RGB(Int(255 * Rnd), Int(255 * Rnd), Int(255 * Rnd))
End Sub
If you need 2 specific background colors, specify the colors for us.
 
Last edited:
Upvote 0
If you need totally random background colors, try:
VBA Code:
Private Sub UserForm_Initialize()
    Me.BackColor = RGB(Int(255 * Rnd), Int(255 * Rnd), Int(255 * Rnd))
End Sub
If you need 2 specific background colors, specify the colors for us.
grey and pink for this project but color its not important i need only how can i do with any 2 color.
 
Upvote 0
VBA Code:
MyColor=Int(2 * Rnd)
If MyColor=0 then Me.BackColor=your color choice  else  Me.BackColor = your other color  ' insert color as required
 
Upvote 0
Solution
VBA Code:
MyColor=Int(2 * Rnd)
If MyColor=0 then Me.BackColor=your color choice  else  Me.BackColor = your other color  ' insert color as required
Thank you so much you saved my life. I will add my code another time by the way :)
 
Upvote 0

Forum statistics

Threads
1,216,094
Messages
6,128,785
Members
449,468
Latest member
AGreen17

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