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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

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