Allow specific text in a textbox

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
416
Office Version
  1. 365
Platform
  1. Windows
Hi
I'm just fine tuning an Exit sub routine, could someone let me know if it's possible to only allow the specific text value "N/A" to be entered in a textbox BUT to exclude all other text values?

Many thanks

Paul
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This is what you need?

VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  If TextBox1.Value <> "" Then
    If TextBox1.Value <> "N/A" Then
      MsgBox "Only allowed N/A"
      Cancel = True
    End If
  End If
End Sub
 
Upvote 0
Hi thanks for your help - again.

Sorry I took so long to reply been away. I'm assuming '<> ' is for less than or greater than which makes sense to use instead on '=' but what was confusing me is why '<>' was used again but as I was typing this reply a lightbulb came on in my head and I actually got what the code is doing lol.

Thanks again Paul
 
Upvote 0
That operator or symbol will be used for the opposite of '='
To know if it is different from.

In the following example compare if a is equal to b
a = b

And in the next example compare if a is different from b
a <> b

I hope it is clearer.

😇
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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