Yes no textbox urgent

TurboDieselOne

Board Regular
Joined
Oct 29, 2008
Messages
52
Hi
I need a way so that a person can only type yes or no in to a text box and then when it tabs to the next text box it turns to ucase. I know the onexit ucase(Variable) but the if me.Texbox1.value = "YES" or "NO" does not seem to work. GOT a 6 Page userform full of yes no textboxes so I can use this code across the board.

Thanks in Advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I assumed you'd complete the If statement, my bad :(

Code:
With Me.textbox1
    If .Value = "YES" Or .Value = "NO" Then
        .Value = UCase(.Value)
    Else
        MsgBox Prompt:="You may only enter YES or NO in this Text Box!", _
               Buttons:=vbCritical, _
               Title:="Error"
        .Value = ""
    End If
End With
 
Upvote 0
Didn't use a Case Statement.... used an IF statement, you could however use a Case Statement....

Code:
With Me.textbox1
    Select Case .Value
        Case "YES", "NO"
            .Value = UCase(.Value)
        Case Else
            MsgBox Prompt:="You may only enter YES or NO in this Text Box!", _
                   Buttons:=vbCritical, _
                   Title:="Error"
            .Value = ""
    End Select
End With
 
Upvote 0
The messagebox is a seperate object to the form and will only go away when you hit Ok on it to clear it. Is it coming up when the form is closed?

You don't need to have the messagebox at all if you dont want.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

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