If Userform Textbox contains text, change it automatically

cdill

New Member
Joined
Jul 10, 2017
Messages
29
I am creating a userform that will allow a user to enter a playing card value into a textbox. But if the user enters "Jack" or "j" or "jack" or "11" (the numeric value of a jack), the text in the box will automatically change to a "J". So to be clear, any input that will indicate a jack, will automatically change to a single capital "J". This will be true for Queen, King and Ace as well so they display as "Q", "K", and "A".

I am trying just the first portion of the code that will change the word jack and I'm having issues. Any ideas?

The textbox is titled CardInput1

Code:
Private Sub CardInput1_Change()        
If InStr(CardInput1.Text, "j" Or "jack" Or "Jack" or "11") Then
        Me.CardInput1.Text = "J"
        End If
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I am creating a userform that will allow a user to enter a playing card value into a textbox. But if the user enters "Jack" or "j" or "jack" or "11" (the numeric value of a jack), the text in the box will automatically change to a "J". So to be clear, any input that will indicate a jack, will automatically change to a single capital "J". This will be true for Queen, King and Ace as well so they display as "Q", "K", and "A".

I am trying just the first portion of the code that will change the word jack and I'm having issues. Any ideas?

The textbox is titled CardInput1

Code:
Private Sub CardInput1_Change()        
[B][COLOR="#FF0000"]If InStr(CardInput1.Text, "j" Or "jack" Or "Jack" or "11") Then[/COLOR][/B]
        Me.CardInput1.Text = "J"
        End If
End Sub
Try it this way...
Code:
[table="width: 500"]
[tr]
	[td]If UCase(CardInput1.Text) = "JACK" Or UCase(CardInput1.Text) = "J" Or CardInput1.Text = "11" Then[/td]
[/tr]
[/table]
You might also want to add an Else block that clears the TextBox for any other input... or at least throw up a MessageBox telling the user the input was invalid.
 
Last edited:
Upvote 0
Actually encountered one more problem. When I want to enter a 10 card I will enter "10", but because I have the code for Ace where it will change a 1 to an "A", the 10 now types out "A0" It changes the "1" into an "A" immediately. Any thoughts of a suggestion?

Here is the code I am now using:
Code:
Private Sub CardInput1_Change() 
              
            If UCase(CardInput1.Text) = "JACK" Or CardInput1.Text = "j" Then
        Me.CardInput1.Text = "J"
        End If
    If UCase(CardInput1.Text) = "QUEEN" Or CardInput1.Text = "q" Then
        Me.CardInput1.Text = "Q"
        End If
    If UCase(CardInput1.Text) = "KING" Or CardInput1.Text = "k" Then
        Me.CardInput1.Text = "K"
        End If
    If UCase(CardInput1.Text) = "ACE" Or CardInput1.Text = "a" Or CardInput1.Text = "1" Then
        Me.CardInput1.Text = "A"
        End If
    
        End Sub
 
Last edited:
Upvote 0
Nevermind. Was able to solve this problem by creating an exit event. Didn't even know that option existed. Thanks everyone.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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