Related
I'm looking to try and do two separate types of validation.
Is it possible to configure validation on a cell to check the first character in that cell and it must be a letter ?
Eg. Anything starting with A-Z case insensitive is fine.
Is is possible to set a cell so it can only contain a number ?
I've got the number check working using =ISNUMBER(J1) that seems to only allow numbers.
I'm trying to check the first character and have tried:
=ISTEXT(LEFT(B10,1)) but that doesn't seem to do what I was hoping..
Thanks
Checking if the whole cell is text is easy with just a simple formula, but if you want to check for only the first letter, then it's more involved.
To ensure that the first character is NOT a number, you can use the custom validation formula
=NOT(ISNUMBER(SUM(LEFT(A1,1),0)))
That will still allow special characters llike $ or & etc. as the first character. If you only want to allow a-z and A-Z as the first letter, then use
=AND(CODE(LEFT(A1,1))>=56,CODE(LEFT(A1,1))<=122)
To allow only numbers, use the built in validation options for Decimal or Whole Number.
Select one or more cells to validate.
Open the Data Validation dialog box.
For this, click the Data Validation button on the Data tab, in the Data Tools group or press
the key sequence Alt > D > L (each key is to be pressed separately).
On the Settings tab of the Data Validation dialog window, select Custom in the Allow box, and enter your data validation formula in
the Formula box.
Click OK.
For text only in a cell build a custom rule with the ISTEXT function, for example:
=ISTEXT(D2)
Custom rule for numbers only in a cell using ISNUMBER.
=ISNUMBER(D2)
Reference: https://www.ablebits.com/office-addins-blog/2017/08/17/use-data-validation-excel-custom-rules-formulas/
I've been given an excel to import on Database, it was exported from an Access DB. in the excel there's a column type_class, in one excel it's good(sheet1), but on another excel which I moved to sheet2 to make VLOOKUP function, I can't tell whether it's a text or a number column from the first sight. the upper-left green-thing is not showing on all cells. but, using ISTEXT function result in text. below is the original column without any changes or formatting, as well as ISTEXT result.
when I use the column in a VLOOKUB function to transfer the Name to the first sheet, only (1010, 1101, 1102,....), hence the cells with the green-mark on the upper-left corner.
I can easly format the key in sheet1 using text-to-columns, cell formatting, and any other way.
but I cannot change the column in sheet2, I tried:
Text-to-Columns
Cell Formatting
VALUE(text), CLEAN(text), TRIM(text), TRIM(CLEAN(text)), CLEAN(SUBSTITUTE())
Multiply by 1
but only the cell with the green-mark changes to a number, the rest stays the same. I browsed the internet but didn't get a solution either.
Edit:
I uploaded what is need to test the case on the drive. you can find it here
Help Appreciated
For your digit strings that you can't convert to text, from the comments it seems there are extra characters in that string not removable by TRIM or CLEAN.
Determine what those character are
Assume a "non-convertible" digit string is in A1
Enter the following formula
B1: =MID($A$1,ROWS($1:1),1) and fill down
C1: = UNICODE(B1) and fill down
From this you can determine the character to use in a SUBSTITUTE function.
For example:
From the above we see that the character code that we need to get rid of is 160.
So we use:
=SUBSTITUTE(A1,CHAR(160),"")
or, to convert it in one step to a number:
=--SUBSTITUTE(A1,CHAR(160),"")
Note If the character code is >255, use UNICHAR instead of CHAR in the SUBSTITUTE function.
Without an example, I use value() to convert what excel takes as text like so:
=value(left(“10kg”,2))
Or the following also works:
=left(“10kg”,2)*1
Note those double quotes should be the straight ones - sorry smartphone is not always smart...
And if leading or trailing spaces are an issue, then trim() is one solution.
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.
I want to sum a column of an Excel tab (depending on the content of another column) which can have different names.
Therefore I dynamically build the name of the tab and then use it in the SUMIF-function.
However, I get #REFERENCE! error and I don't know why?! I can reference single cells this way but not a range which I have to in this case. Can someone see what I'm doing wrong or maybe help me with a workaround?
=SUMIF(INDIRECT(CHAR(39)&Settings!$D$3&"-V"&L$7&CHAR(39)&"!B3:B100";FALSE);B44;INDIRECT(CHAR(39)&Settings!$D$3&"-V"&L$7&CHAR(39)&"!H3:H100";FALSE))
Area to sum as you can see below:-
Cell where I want the sum to be:-
=SUMIF(INDIRECT("'"&YEAR($E$5)&"-V"&L$7&"'!$M$3:$M$10"),"*"&$C9,INDIRECT("'"&YEAR($E$5)&"-V"&L$7&"'!$O$3:$O$10"))
This is the correct use (note I have used the actual character ' instead of CHAR(39))
The wildcard is used to match anything before the cells content as your data contains PL before it and also note the use of absolute referencing.
You will need to change the , to ; to match your regional settings...
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)