disable controls on userform

Molden

Active Member
Joined
Jun 20, 2006
Messages
372
Hi All,

Does anyone know how to disable different parts of a userform?

I dont really want to go through each control as I reckon it will be handy code to have in the future if I need to add more but so far my code is:

Private Sub UserForm_Activate()

With Sheet2

n = 3

Do

If .Cells(n, 8) = "Completed" Then
Me.ComboBox4 = .Cells(n, 9)
me.combobox1.enabled=false
me.combobox2.enabled=false
me.combobox3.enabled=false
me.combobox4.enabled=false
me.dtpicker1.enabled=false
me.dtpicker2.enabled=false
End If

n = n + 1

Loop Until .Cells(n, 7) = ""

End With
End Sub

Thanks in advance

Michael
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,151
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You can disable all controls using a for each loop:
Code:
Dim ctl as msforms.control
For each ctl in me.controls
ctl.enabled = false
next ctl
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
You can use a combination of loop through all controls in your userform and checking their types.
For example,
Code:
Dim cCont As Control
For Each cCont in Me.Controls
    If TypeName(cCont) = "ComboBox" Then
        cCont.Enabled = False
    End If
Next cCont

from http://www.ozgrid.com/VBA/control-loop.htm
 

Watch MrExcel Video

Forum statistics

Threads
1,123,385
Messages
5,601,331
Members
414,446
Latest member
CRAVIN

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
Top