Userform VBA Check if All or None of Textboxes are Filled

tryingmybest418

New Member
Joined
Jan 22, 2018
Messages
32
Hi all,

I have a userform with a group of 9 text boxes that I would like to check.

If the user has left them all blank or filled them all, they should be able to click "OK" and complete the form.
If the user has only filled in 1-8 of the textboxes, I'd like a message box to display telling them they must clear all the fields or complete all the fields.

Is there a way I could check this?

Let me know if my explanation is unclear!

Thanks!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
something like this


Code:
For Each cCont In Me.Controls
    If TypeName(cCont) = "TextBox" and cCont.value = vbNullString then msgbox "Please fill " & ccont.name & " out"
Next cCont
 
Upvote 0
Thanks for the reply.

I could be wrong, but this looks like it throws the message for any and all that are empty.

I'm looking for something along the lines of, "IF all 9 are empty OR all 9 are filled, THEN do nothing, ELSE message box "
 
Upvote 0
oh, gotcha. yes you are correct that's what its doing.

in that case you can do something like this.

Code:
i = 0

For Each cCont In Me.Controls
    If TypeName(cCont) = "TextBox" and cCont.value = vbNullString then i = i + 1
Next cCont

If i <> 0 and i <> 9 then msgbox "Please Check"
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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