Raani has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
VBA if statement within userform
Hi,
I have a userform where there is one drop down box and a text box beneath it. I'm trying to write an if statement code where, if the 'Standard' option is selected the user has to complete the textbox below with further information, however if any of the other items in the list are selected then the textbox says "N/A". This is the code I have:
Private Sub cboPriority_Change()
If cboPriority.Value = "Standard" Then
txtBooked.Value = ""
Else: txtBooked.Value = "N/A"
End If
End Sub
However when 'Standard' is selected the user is unable to type anything in the textbox, I realise this is because of the "" value I've put in the code but how do I amend this so the textbox can be typed in?
Thanks for your help
Raani
RE: VBA if statement within userform
Hi Raani
Thanks for getting in touch. I was surprised this Excel VBA code didn't work. To get round this I added another command enabling or disabling the textbox to ensure control was passed back to the user.
Here's the resulting code:
Private Sub cboPriority_Change()
If cboPriority.Value = "Standard" Then
txtBooked.Value = ""
txtBooked.Enabled = True
Else
txtBooked.Value = "N/A"
txtBooked.Enabled = False
End If
End Sub
Give it a try and let me know how you get on.
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector