Data validation and numbers + hyphens

Jordytee

New Member
Joined
Nov 8, 2018
Messages
6
Hi there all, i want to set a data validation rule so that only the following number sequence can be entered to a cell: 000000-00
the hyphen is a must, if i didnt need the hyphen I would be fine setting this up. Any ideas?

I use the data validation from the ribbon, and need a custom formula
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi
Welocome to the board

For ex., for B2:

=AND(LEN(B2)=9,ISNUMBER(-MID(B2,ROW(INDIRECT("1:6")),1)),MID(B2,7,1)="-",ISNUMBER(-MID(B2,8,1)),ISNUMBER(-MID(B2,9,1)))
 
Upvote 0
I think this will work:
=AND(LEN(REPLACE(B2,7,1,""))=8,MID(B2,7,1)="-",ISNUMBER(SUBSTITUTE(B2,"-","")+0))
 
Upvote 0
Hi Scott

I think that will work for most of the values that the user might try, but to be sure that the pattern is respected I believe you have to check each character separately.

Your formula accepts:

1,2345-67
12.345-67
12345-67 (space before)
123456-7 (space after)
2019-1--1
10:21:-23
123456-e2
12345e-+3
+1234-56 (space before)
 
Upvote 0
Hi Mike

In the case of your formula you can trick Value() with the exponential

Try:

123456-e7
1.23e8-11


Like in Scott's case, maybe not really important, but always good to know.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,592
Members
452,653
Latest member
craigje92

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