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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

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