disable controls on userform

Molden

Active Member
Joined
Jun 20, 2006
Messages
373
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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

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