KeyAscii key restrictions with named range

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I have been using the following code to only allow the user to enter numbers into a text box on a userform. I am needing to use a similar code to this on a named range to restrict the user from entering certain characters. I am not too sure how to manipulate the following code to make it work on a named range...

Code:
Private Sub txtFax_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  If InStr("0123456789.", Chr(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Does anyone know how to completely block particular characters from being typed into a named range?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Short of setting a low level keyboard hook, you can't. You could just use data validation, or use the worksheet_change event to validate the data after it's entered (which is actually what I would do on the form too)
 
Upvote 0
That was my fear....

Well I guess this brings up another question. I have a good data validation formula that worked...kinda :-/

Code:
=ISNA(MATCH(TRUE,(ISNUMBER(FIND($BH$666:$BH$675,ClientFName))),0))

This is supposed to refer to a list of invalid characters and prevent the user from entering them. Only problem is it works fine until I save and reopen the document. Once I reopen the document it stops working??

The only way I can make it work again is to remove and reapply the validation. Any ideas why this would happen?
 
Upvote 0
Did you uncheck the ignore blanks option?
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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