Excel VBA interior colour Userform controls

Aretradeser

Board Regular
Joined
Jan 16, 2013
Messages
176
Office Version
  1. 2013
Platform
  1. Windows
In a Userform I use several TextBoxes and ComboBoxes. If in the ComboBox1 any country is selected, except "ESPAÑA" or "PORTUGAL", the TextBox7 and the ComboBox6 are disabled; by means of this code:

VBA Code:
Private Sub VisibilidadControles()
    Me.TextBox7.Enabled = (Me.ComboBox1 = "ESPAÑA" Or Me.ComboBox1 = "PORTUGAL")
    Me.ComboBox6.Enabled = (Me.ComboBox1 = "ESPAÑA" Or Me.ComboBox1 = "PORTUGAL")
End Sub

Private Sub ComboBox1_Change()
    VisibilidadControles
    ComboBox2.Value = ""
End Sub

What code would have to be added so that both TextBox7 and ComboBox6, are coloured red when an item other than those two countries is selected?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,
untested but see if this update to your code does what you want

VBA Code:
Private Sub VisibilidadControles()
    Dim m As Variant
    m = Application.Match(Me.ComboBox1.Text, Array("ESPAÑA", "PORTUGAL"), 0)
    With Me.TextBox7
        .Enabled = Not IsError(m)
        .BackColor = IIf(.Enabled, vbWindowBackground, vbRed)
    Me.ComboBox6.Enabled = .Enabled
    Me.ComboBox6.BackColor = .BackColor
    End With
End Sub

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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