Allowing only numbers and just1 letter in a cell

machiax

New Member
Joined
Sep 8, 2022
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Hi all , New to VBA
I wish to allow only numbers and the letter "P" in a cell. and if that rule is not complied with, a message appears that says "please only use numbers or the letter P".

ty for help
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You don't need vba for that, just simple data validation using a formula as a custom validation rule.
Excel Formula:
=AND(SEARCH("p",A1),--SUBSTITUTE(A1,"p","",1))
 
Upvote 0
You don't need vba for that, just simple data validation using a formula as a custom validation rule.
Excel Formula:
=AND(SEARCH("p",A1),--SUBSTITUTE(A1,"p","",1))
i have to do it with macro, because this condition is part of biggest macro in a userform text box.
 
Upvote 0
because this condition is part of biggest macro in a userform text box.
It would be a good idea to specify things like this in your question rather than adding them later. That way you might get what you actually need instead of the incorrect thing that you asked for.
 
Upvote 0
I believe that the only way to do what you want is with a regular expression, however it is not something that I understand well enough to write the code that you need. It is possible that your thread will be viewed by another member who will be able to help you, although it is less likely with a thread that already has replies.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,837
Members
449,193
Latest member
MikeVol

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