Conditional Required Fields In UserForm

mrmarc

Board Regular
Joined
Feb 3, 2014
Messages
79
I have a made a userform with 8 groups of 1 Combobox and 2 Textboxes.

I want to create required fields, so that if one of the input boxes within each group is filled in, the rest in that group must be filled in as well. Here is what I have coded:

'Group 1


If cmb1.Value <> "" And txt2.Value = "" Or txt2Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


If txt2.Value <> "" And cmb1.Value = "" Or txt2Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


If txt2Hd.Value <> "" And cmb1.Value = "" Or txt2Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


'Group 2


If cmb2.Value <> "" And txt3.Value = "" Or txt3Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


If txt3.Value <> "" And cmb2.Value = "" Or txt3Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


If txt3Hd.Value <> "" And cmb2.Value = "" Or txt3Hd = "" Then
MsgBox " You must fill in all three Fields (Grower, Case and Harvest Date)"
Exit Sub
End If


With the "Group 1" code alone, my conditional required fields work (within that group). BUT when I introduce the "Group 2" code, even when all of Group 2 is filled out, I cannot enter the data. I get the msgbox "You must fill in all three Fields (Grower, Case and Harvest Date)"

Not Sure What Im doing Wrong. Please Help! Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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