Data Validation In Excel to a format ###-###-###-### - excel

Apologies if this is a common sense question, checked the web but couldn't find the exact answer I am want. I am trying to make excel only allow a number to be entered in the following format [ ###-###-###-### ] (For example, something like 102-204-304-101). I have got something similar where if I highlight a cell and go to (Format Cells -> Custom -> and in the "Type field" I enter 000"-"000"-"000"-"000. This works if somebody enters 102204304101, it will translate into 102-204-304-101. But I want another user to explicitly type the hyphens. I would guess it can be done in the "Data Validation" section under the Data Ribbon (Note I am using Excel 2010), but couldn't figure out how to do this. Would be grateful if anybody can kindly provide any tips. Thank you in advance.

Based on Excel 2007:
=AND(MID(A1,4,1)="-",MID(A1,8,1)="-",MID(A1,12,1)="-")
as a formula under Validation criteria , Allow: Custom, validates for hyphens in positions 4, 8 and 12.

Use this validation formula (replacing D11 with appropriate cell):
=IF(MID(D11;4;1)&MID(D11;8;1)&MID(D11;12;1)="---";ISNUMBER(VALUE(-0,1&MID(D11;1;3)&MID(D11;5;3)&MID(D11;9;3)&MID(D11;13;3)&1E+100)))
This ensures slashes and numbers.
You may have to change , to ; and . to , according to your local.

as each character has a definite range (0-9 and -) we can use the ASCII values of the characters to check the text. We also check the length, and, if the string is too short (producing error in the eqation, we wrap the whole thing in an IFERROR.
Building this up, we use CODE and MID to check each character:
Lower range: CODE(MID(A1, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},1)) >= {48,48,48,45,48,48,48,45,48,48,48,45,48,48,48}
Upper Range: CODE(MID(A1, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, 1)) <= {57,57,57,45,57,57,57,45,57,57,57,45,57,57,57}
length: LEN(A1)=15
has to pass all tests: AND
and can't produce an error IFERROR
Putting that all together, we get:
=IFERROR(AND(LEN(A1)=15, CODE(MID(A1, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},1)) >= {48,48,48,45,48,48,48,45,48,48,48,45,48,48,48}, CODE(MID(A1, {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}, 1)) <= {57,57,57,45,57,57,57,45,57,57,57,45,57,57,57}),FALSE)
Put this in the cell next to the place you want them to enter the code (B1 in this example), and put the validation as =B1

If the Cell is I10
DATA >> DATAVALIDATION : CUSTOM
=IF(LEN(I10)<=12;TEXT(I10;"000-000-000-000");FALSE)

Related

EXCEL: Count Range; but Exclude blanks AND a specific string

Excel Version: Microsoft 365 bundle (V 2106 Build: 14131.20278)
I'm trying to create an Excel formula that outputs a number onto a single cell (B11); the formula must:
Count the number of cells that HAVE DATA on a given range [B2:B8];
Therefore, IT must NOT count non-blank cells; but must also NOT INCLUDE cells with a specific string (in this case the string would be "N/A") ;
The formula must also count the number of line breaks [so Char(10)] present on that given range.
I understand that it's not conventional to count inputted line breaks for a range; but that's what I need.
See the attached image:
RANGE = In this example, the range of (non-blank AND non-"N/A") cells I want to count go from B2 to B8.
Cell w/ Formula: B11
As of now, I only have the following formula done.
=SUM(LEN(B2:B8)-LEN(B2:B8;CHAR(10);""))+(LEN(B2:B8)>0))
This formula outputs == "9" (i.e., 9 line breaks: ignores blanks, but includes the string "N/A")
This formula allows me to count all line breaks present on that given range (so, it doesn't count blank/empty cells), but it obviously doesn't exclude the specific string "N/A".
Expected output == "8" (i.e., 8 line breaks: ignoring blank cells AND cells with the string "N/A")
I suppose this could be accomplished with an "IF", but I haven't figured it out yet.
Thank you for your time!
PS: I tried to make a table in here, but I was not able to add line breaks inside a single cell; so, I ended up resorting to an image to explain my point, sorry about the inconvenience!)
Right, since you have got access to Microsoft 365, try the following:
=SUM(FILTER(1+(LEN(B2:B8)-LEN(SUBSTITUTE(B2:B8,CHAR(10),""))),LEN(B2:B8)*(B2:B8<>"N/A"),0))
Nicely layed out question btw, and a fun little issue to work on. Hopefully the above helped you out.
Just for a different approach:(edited after #ScottCraner pointed out it didn't account for N/A)
=LET(x,FILTER($B$2:$B$8,B2:B8<>"N/A"),
y,TEXTJOIN(CHAR(10),TRUE,x),
z,SUBSTITUTE(y,CHAR(10),""),
LEN(y)-LEN(z)+1)
Of course, if you have a lot of data, TEXTJOIN will fail if the resultant string is > 32,767 characters
Should be able to do this with a simple COUNTIF (or COUNTIFS if you want to add more criteria to count against).
Try =COUNTIF($B$2:$B$8, "<>N/A")
EDIT1: As pointed out by cybernetic.nomad, a better approach to dealing with non-numeric data will be COUNTA. Another solution might be to just filter the whole data with something like:
=COUNTA(FILTER($B$2:$B$8, $B$2:$B$8<>"N/A"))
EDIT2: As pointed out by Scott Craner, this solution does not account for line breaks. You can add those in by using:
=COUNTA(FILTER($B$2:$B$8, $B$2:$B$8<>"N/A"))+
SUM(LEN($B$2:$B$8)-LEN(SUBSTITUTE($B$2:$B$8,CHAR(10),"")))

Excel 2010 Data Validation allow specific layout

I want to apply data validation to reference numbers, to force the following layout (ideally uppercase only):
XX_NNX-XX_NNN_NN-XXX
X = Numbers
N = Letters
Ex: 12_AB1-23_ABC_AB-123
The following custom formula allows all of it except for numbers - is there any workaround for this?
I don't want to use * since it allows for more characters than I want.
=COUNTIF(A1,"??_???-??_???_??-???")
You can choose AND to add a condition to the function you have already written. e.g. following shall test the positions which shall be numeric.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0))
Notes: This is fairly basic approach and may need some tweaks if you have cases involving usage of decimals etc.
Edit: You can try below approach for checking upper case text in specified positions.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),INDEX(FREQUENCY(-CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),{-91,-65,0}),2)=7)
Edit2: This turned out to be tougher than I had imagined. Following formula works in DV for cell A1.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),MIN(FLOOR(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),65))=65,MAX(CEILING(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),90))=90)
But due to some quirk, Excel won't let me simply paste it. So I wrote a small code for the same which applies DV to cell A1 and surprisingly it accepts that same long formula through code. Make sure that you delete DV in the cell before you run this code.
With Range("A1")
.Value = "12_AB1-23_ADC_AZ-123"
.Validation.Add xlValidateCustom, , , "=AND(COUNTIF(A1,""??_???-??_???_??-???""),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),MIN(FLOOR(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),65))=65,MAX(CEILING(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),90))=90)"
End With
Once in there, you can get it in any other cell by simply doing copy >> Paste Special >> Validation.
For clarity, I use Excel 2016.

Excel - Data Validation Format

I need to set data validation on an excel cell to be a specific format. I haven't been able to figure it out myself so far.
The requirements are:
20 characters in length
first 4 characters have to be numeric
characters 5&6 have to be '00'
characters 7-18 need to be alphanumeric
characters 19&20 need to be numeric
Can anyone help me with this?
Use a custom formula like:
=and(Len(A1)=20,isnumber(left(A1,4)+0),mid(A1,5,2)="00",isnumber(right(A1,2)+0))
and make sure to uncheck the Ignore blank option.
Note: this would actually allow any characters for 7-18. If it has to be restricted to A-Z and 0-9 that will require an addition to the formula.
Edit:
Based on the clarified requirements, I would suggest VBA be involved. Add a new module with this function:
Function IsValid(InputText As String) As Boolean
IsValid = UCase$(InputText) Like "####00[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]##"
End Function
Then select the first cell to which you want to apply the data validation - I'll assume A1. Using Name Manager, define a name called IsValidEntry using the formula:
=IsValid(A1)
If your DV cell is not A1, use the appropriate address here but do not include any $ signs.
Now in the DV settings you can choose Custom, uncheck the Ignore Blanks option, and use =IsValidEntry as the source.

Calculate Text formula (NO VBA and NO Evaluate)

I am using Excel to calculate a string value where Evaluate() works fine but I am not allowed to use evaluate() in the Name Manager and I am not allowed to use it in VB A because the file gets converted to .xls. Here is the issue.
I have 100 s of a long formula example:
($F$10+0)+($F$11+0.125)+($F$10+0.0625)
which i need to evaluate the values between the brackets separately.
I am able to separate the formula to
A1 is ($F$10+0)
A2 is ($F$11+0.125)
A3 is ($F$10+0.0625)
I would like to put an "=" sign in front of this string and calculate the values of A1, A2, and A3.
However I am not allowed to use function EVALUATE() in the File Manager, it does not work in the cells and I am not allowed to use VB A to code the formula.
is there any replacement for evaluate that I can use?
thanks
Welcome to the dark side of Excel.
If you cannot use:
1) VBA
2) Macros
3) Evaluate()
4) File Manager / Define Name
Then there are no simple formulas that can help you (plus you can't make your own). Microsoft has purposely not addressed this issue for many many years.
So you are left to your own devices to create your own parser in Excel cells.
This can be very difficult if you have varying types of formulas that can change signs, or amount of addressed cells, or any number of other craziness that formulas can take.
However... if you have a minimum number of deviations for how the formula is expressed... you can write something that will do the trick.
This comes with a caveat... the formula must be provided with the same parameters each time. And what you gave as examples, has the structure defined exactly the same for each formula.
So therefore, using your examples, you can write this code in column A2:
=INDIRECT(MID(A1,SEARCH("$",A1),SEARCH("+",A1)-SEARCH("$",A1)),TRUE)+MID(A1,SEARCH("+",A1)+1,LEN(A1)-SEARCH("+",A1)-1)
Then you can copy that code over to B2 and C2.
This will give you the correct math as if it was a formula.
The structural parameters that are needed for this to work are:
1) The cell address must always start with a dollar sign $
2) The cell address must be immediately followed by a plus sign +
3) Only a single addition is done as the formula
4) The operand after the plus sign must be numeric
5) The formula must end with a Parenthesis )
6) It can't hurt to begin with a Parenthesis either (
And since all of your formulas adhere to this structure... the formula I provided will work.
If you need to change item 3 to also allow for 'subtraction', then you are going to need to add if statements to the formula and it's going to become complicated very quickly. Impossible? No. But a huge mess? Yes.
Anyway, this should work with all of your restrictions that you have. That is... if your formulas don't deviate from the structure that has been provided. If you have different formula structures, you'd need to let us know about them... or better yet, write your own code.
Hope this helped. :)

Excel Vlookup , too few arguments error

When I try to enter Vlookup formula manually in Excel, I get the following error;
excel manual vlookup error. This error appears while I'm defining the second element of the formula from another excel file and it doesn't let me to define the area.And it directs me to use formula wizard, however it's not useful and efficient for me. Has anyone experienced this problem before?
You may find the formula I try to use as below;
=vlookup(S2;'[Copy of Material Master_S112.xlsx]q_S112'!$G$2:$I$7
after this point it doesn'let me to make any change and directs me to formula wizard.
Thank you for your help in advance
VLOOKUP() takes 4 arguments:
Value to seek.
Target range.
Number of result column relative to the first column of target range. E.g. if your target range is $G:$I and you need results from column H this parameter should be 2, if you want results from column I - then 3.
Parameter specifying whether you need exact (TRUE) or approximate (FALSE) match. Set it to FALSE in most cases.
And of course you need closing parenthesis ) at the end.
So the correct formula should look something like this:
=VLOOKUP(S2;'[Copy of Material Master_S112.xlsx]q_S112'!$G$2:$I$7;3;FALSE)
If you use Ctrl-Shift-Down after you have started to enter the second parameter you will get the "you have entered too few arguments" message.
You can only use Ctrl-Shift-Down after selecting a cell but before you have entered anything for the second VLOOKUP parameter.
As I mentioned in my comment, arguments in Excel formulas are separated by commas, not semicolons.
For example,
=VLOOKUP(S2, '[Copy of Material Master_S112.xlsx]q_S112'!$G$2:$I$7, 2, FALSE)
Thank you for all your answers. It's kind of interesting but, I have to hit at first shift and then control not to get this error. It wasn't like that before but when I hit control first and then shift+down it gives the error. But at least it works like this.
if you use win 10 , you must change the regoin configoration .
in control panel > region >formats> additional setting> list separator
change content to ";"

Resources