Excel customer data validation for chars and numbers - excel

I am trying to validate a combination of char and numbers that looks like this XXXX0000000.
I have tried this formula; =OR((LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11).
The error message I receive is as follows:
excel error message

Title: "Excel customer data validation for chars and numbers"
...I have the feeling it's not just about validating XXXX0000000 but it's about the pattern of characters and numbers. Therefor try:
Formula in B1:
=IF(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")),"Invalid","Valid")
Where:
//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''] - Check if when we translate the first 4 characters to nothing this also equals empty string;
[string-length()=11] - Check that node is 11 characters long;
[substring(.,5)*0=0] - Check that substring from 5th position onwards equals zero when multiplied by zero.
Note: FILTERXML() is case sensitive and is currently checking for uppercase alpha-chars.
EDIT:
To use this in data-validation; Ditch the IF() since you don't need that in validation and nest the remainder in NOT():
=NOT(ISERROR(FILTERXML("<t><s>"&A1&"</s></t>","//s[translate(substring(.,1,4), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','')=''][string-length()=11][substring(.,5)*0=0]")))
When you select your range, make sure the validation rule has the topleft cell in the reference.

You have two formulas but no joining of them
IE you have an OR formula
=OR((LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
You also have an AND formula
=AND(LEFT(B2,3)="XXXX",LEN(B2)=11)
Which will return a true/false answer
when you work through it you are being given a return of:
=True(or false), true (or false)
That isn't a formula and is causing the error output
I think you want to use an IF statement to join them and get an output as desired:
E.g.
=If(OR(LEFT(B2,3)="XXXX",LEN(B2)=11),AND(LEFT(B2,3)="XXXX",LEN(B2)=11), DO SOEMTHING IF TRUE, DO SOMETHING IF FALSE)

I suggest this:
OR(LEFT(B2,3)="XXX",LEN(B2)=11,AND(LEFT(B2,3)="XXX",LEN(B2)=11))
It corrects the number of characters error and sorts the logic.

Related

Excel - multiple value search across multiple columns or one column with multiple values

I have 7 criteria = TMO-1 through to TMO-7
I have two scenarios to search from.
i have either got a single excel with TMO-6, TMO-201, TMO-67,... etc (some have a lot of values)
or i have split the cell up so the values are all in individual cells such that [TMO-6][TMO-201][TMO-67] etc
I have tried two equations from each. for the first one (the preferred solution) i have tried:
=IF(IFERROR(SEARCH("TMO-1",AB8),0) > 0, "TMO-1",IF(IFERROR(SEARCH("TMO-2",AB8),0) > 0, "TMO-2", "false"))
the problem with that is it finds anything that starts with TMO-1, so will show true if TMO-12 is in the cell.
For option 2 i tried:
=IF(AB9:AR9=TMO-1, TMO-1, IF(AB9:AR9=TMO-2, TMO-2, IF(AB9:AR9=TMO-3, TMO-3,IF(AB9:AR9=TMO-4, TMO-4, IF(AB9:AR9=TMO-5, TMO-5, IF(AB9:AR9=TMO-6, TMO-6, IF(AB9:AR9=TMO-7, TMO-7, "N/A")))))))
and i get the error #spill
any ideas ?
Assuming:
ms365 (Hence the #SPILL error);
The option between concatenated values or seperated (hence AB8 against AB9:AR9);
All numbers are prepended with TMO-;
You are looking for the 1st match in sequence (1-7);
If no match is found, you want to return "Not Found".
First thing that came to mind is to just keep the comma-seperated data in AB8 and use a simple trick to concatenate the delimiters with the sequence:
=ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&","))
To put that in practice, try:
Formula in B1:
=IFERROR(MATCH("X",IF(ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&",")),"X"),0),"Not Found")
Other options:
=#IFERROR(SORT(FILTERXML("<t><s>"&SUBSTITUTE(A1,", ","</s><s>")&"</s></t>","//s[substring(.,5)<8]")),"Not Found")
Or, using the insider BETA-functions:
=LET(X,MIN(--DROP(TEXTSPLIT(A1,"-",", "),,1)),IF(X<8,"TMO-"&X,"Not Found"))

Excel Multiple If Statements showing False

I have this IF statement:
=IF(AG3<=7,"1",IF(15<=AG3<=21,"2",IF(22<=AG3<=28,"3",IF(29<=AG3<=35,"4",IF(36<=AG3<=42,"5",IF(43<=AG3<=49,"6",IF(50<=AG3<=56,"7")))))))
but either it gives me a 1 or "FALSE"
All the values are within the ranges and should be showing various numbers
Excel does not use 50<=AG3<=56. The way Excel will read this is it will resolve AG3<=56 which will resolve to TRUE or FALSE which have the values of 1 and 0 respectively. And since 50 is greater than both those it will always return FALSE and since you did not specify a final false argument Excel returns FALSE
It needs to be AND(50<=AG3, AG3<=56)
Also "1" returns a number as text and not a true number, remove the quotes.
So:
=IF(AG3<=7,1,IF(AND(15<=AG3,AG3<=21),2,IF(AND(22<=AG3,AG3<=28),3,IF(AND(29<=AG3,AG3<=35),4,IF(AND(36<=AG3,AG3<=42),5,IF(AND(43<=AG3,AG3<=49),6,IF(AND(50<=AG3,AG3<=56),7,"Value not in specs")))))))
But based on your criteria you could use:
=IF(OR(AND(AG3>=8,AG3<=14),AG3>56),"Not to Spec",MATCH(AG3,{-1E+99,15,22,29,36,43,40}))
Don't use Nested IFs if you can avoid it. Instead, use a banded VLOOKUP: it's many times more efficient, and a heck of a lot simpler to troubleshoot. Something like the answer here:
Excel IF statement Not returning the appropriate Value
In your case, here's your lookup list:
Note that since you haven't specified what should happen between 8 and 14 or over 57 I have simply put =NA() in those bands.
And here's the result for a range of numbers:
...and here's the formula that was used in the second column of that second table (using table notation):
=VLOOKUP([#Value],Table3,2,TRUE)

Remove all text and characters except some

I have here some text strings
"16cg-301 -request","16cg-3368 - for review","16cg-3684 - for process"
what i would like to do is to remove all the text and characters except the number and the letters "cg" and - which is within the reference code.
If the string you want to extract is always before the first space in the full string then you can use SEARCH and LEFT to extract your reference code:
=LEFT(A1,SEARCH(" ",A1)-1)
This formula would take 16cg-3368 from 16cg-3368 - for review.
I suggest using something like suggested here
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
With a replace regex similar to this
[^\dcg]*
or a match regex like this
^([0-9cg- ]+).*
else you could also work with a strange formule similar to this
=CONCATENATE(IF(NOT(ISERROR(SEARCH(MID(A2;1;1);"01234567890cg-")>0));MID(A2;1;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;2;1);"01234567890cg-")>0));MID(A2;2;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;3;1);"01234567890cg-")>0));MID(A2;3;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;4;1);"01234567890cg-")>0));MID(A2;4;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;5;1);"01234567890cg-")>0));MID(A2;5;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;6;1);"01234567890cg-")>0));MID(A2;6;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;7;1);"01234567890cg-")>0));MID(A2;7;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;8;1);"01234567890cg-")>0));MID(A2;8;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;9;1);"01234567890cg-")>0));MID(A2;9;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;10;1);"01234567890cg-")>0));MID(A2;10;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;11;1);"01234567890cg-")>0));MID(A2;11;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;12;1);"01234567890cg-")>0));MID(A2;12;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;13;1);"01234567890cg-")>0));MID(A2;13;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;14;1);"01234567890cg-")>0));MID(A2;14;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;15;1);"01234567890cg-")>0));MID(A2;15;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;16;1);"01234567890cg-")>0));MID(A2;16;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;17;1);"01234567890cg-")>0));MID(A2;17;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;18;1);"01234567890cg-")>0));MID(A2;18;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;19;1);"01234567890cg-")>0));MID(A2;19;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;20;1);"01234567890cg-")>0));MID(A2;20;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;21;1);"01234567890cg-")>0));MID(A2;21;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;22;1);"01234567890cg-")>0));MID(A2;22;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;23;1);"01234567890cg-")>0));MID(A2;23;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;24;1);"01234567890cg-")>0));MID(A2;24;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;25;1);"01234567890cg-")>0));MID(A2;25;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;26;1);"01234567890cg-")>0));MID(A2;26;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;27;1);"01234567890cg-")>0));MID(A2;27;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;28;1);"01234567890cg-")>0));MID(A2;28;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;29;1);"01234567890cg-")>0));MID(A2;29;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;30;1);"01234567890cg-")>0));MID(A2;30;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;31;1);"01234567890cg-")>0));MID(A2;31;1);"");IF(NOT(ISERROR(SEARCH(MID(A2;32;1);"01234567890cg-")>0));MID(A2;32;1);""))
only works by now for less than 33 signs.
problem here will be that you will get unexpected behavior like this:
123cg-123 - Process => 123cg-123-c
after rereading , I think you should try an other approach than described in the question ;-)
If you want to return everything up to and including the last digit, then try:
=LEFT(A1,LOOKUP(2,1/ISNUMBER(-MID(A1,seq,1)),seq))
seq is a named formula: Formula ► Define Name
Name: seq
Refers to: =ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))
seq returns an array of sequential numbers from 1 to 255.
mid(a1,seq,1)
returns an array consisting of the individual characters in the string in A1. The leading minus sign converts the digits from strings to numbers.
The lookup function will then return the position of the last digit

Excel Nested IF AND

I have the following formula:
=IF(AND(A1=0,A3="","1 item"),
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items"))))
3 combinations of cell values in A1 and A3 return text which I'm calling "1 item"
Only 1 combination of cells value returns text which I'm calling "2 items".
The only combination to return "2 items" is where A1=1 AND A3="".
The formatting is wrong but I'm not sure where.
Any help would be greatly appreciated.
this is the correct formula -
brackets of AND() were not properly closed.
=IF(AND(A1=0,A3=""),"1 item",IF(AND(A1=0,A3="Exclude"),"1 item",IF(AND(A1=1,A3="Exclude"),"1 item","2 items")))
Excel's IF expects three parameters: Condition, What to do if condition is TRUE, and what to do if condition is FALSE.
I'll re-format your formula so you can see where the error is:
IF( AND(A1=0,A3="","1 item") ,
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items")
)
)
)
As you can see
For the first IF you are not providing what to do if condition is FALSE,
The same for the second IF,
The third IF has no definition of what to do if the condition is TRUE or FALSE.
Hope this helps you.
UPDATE
Following your comment (which is still not clear to me), hereinafter I'm providing simple rules you may use to construct your formula correctly:
Write your formula as a piece of text (like the example I show above) so that you can easily read, edit and verify it,
Remember that Excel's IF has three parameters: Condition, result when condition is TRUE and result when condition is FALSE,
Within any of these three parameters, you can include whatever you want PROVIDED that the result is compliant with what the function expects for that parameter; for instance, writing for the first parameter 3=8 is completely legal since the result is FALSE (while 4=2*2 would yield TRUE).
Having this in mind, here is the formula I think you are looking for (WARNING!!! I'm not sure I understood what you need, but if not, changing it should be very easy for you now):
IF(AND(A1=1,A3=""),"2 items","1 item")
This is based on your wording: The only combination to return "2 items" is where A1=1 AND A3="".

excel nested vlookup function using formats and NA Arguments

I placed an example below, of which I don't necessarily 'need' to work, but I don't like that I can't get it to work. I've attempted to use the ISNA function, but am having little success since I
=IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Additional Credit… Research","No Credit Exists")))
I really would like to have a response to each formula, am I using the wrong functions or the wrong format?
To avoid repeating the VLOOKUP function multiple times you can use SIGN and CHOOSE in this scenario like this
=CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research")
If you add the VLOOKUP result to J3 you will get a negative number, zero or a positive number, SIGN function will return -1, 0 or 1 respectively for those and then adding 2 gives 1, 2 or 3 so we can use CHOOSE function to convert 1,2 or 3 to the relevant text value
That formula still gives #N/A error if H3 isn't found in Credit!H:H so to avoid that use IFERROR function (assumes Excel 207 or later), so final version becomes:
=IFERROR(CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research"),"No credit exists")
perhaps
=IF(ISNA(MATCH(H3,Credit!H:H,0)),"No Credit Exists",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research","Additional Credit… Research")))
the MATCH part looks for the value H3 in Credit!H:H and if it isn't there the ISNA handles the resulting error and returns "No credit exists"; the rest is basically just a tweak of the original formula

Resources