Check if a cell substring is numeric - excel-2010

I have a cell that should contain values like 123456789WA. The first 9 characters should always be numbers, and the last 2 should be WA. I can check the length to make sure it's 11, I can check the last two characters to make sure they're "WA", but I can't figure out how to check the first 9 to make sure they're numbers. ISNUMBER doesn't work because the cell is text, so it always gives a false. Here's my cell formula:
=IF(LEN(A2)<>11,"Not 11 char",IF(RIGHT(A2,2)<>"WA","Missing 'WA'",IF(ISNUMBER(LEFT(A2,9)),"","Left not numeric")))
I can do it in VBA, but this is something I'm passing off to very unsophisticated users, so I need to make it work in a cell. Any ideas?

With a value in A1, the first 9 characters can be tested with:
=IF(ISERROR(--LEFT(A1,9)),"not all numbers","all numbers")

Related

Add leading zeros in cells with non digits

I have two cells that need to be merged into one, but the formatting needs to be updated. In one cell there are category IDs and in the other cell are subcategory IDs. None of them are formatted to have leading zeros, which isn't too big of a deal because I can just use the number format for that. The problem is that the subcategories sometimes have a letter at the end. Number format completely ignores these and just leaves them be. Is there a formula/combination of formulas I can use to get data to look like this?
Category
Subcat
Output
1
1
01-01
4
12
04-12
21
1
21-01
21
1b
21-01b
EDIT
Sorry about the previous answer. This one is correct
=ArrayFormula(IF(A2:A<>"", IF(LEN(A2:A)=1,"0"&A2:A,A2:A)&"-"&IF(REGEXMATCH(B2:B&"","^\d{1}$|^\d{1}\D")=TRUE,"0"&B2:B,B2:B),""))
WRONG (You can use this)
=ArrayFormula(IF(A2:A<>"", IF(LEN(A2:A)=1,"0"&A2:A,A2:A)&"-"&IF(LEN(B2:B)=1,"0"&B2:B,B2:B),""))
try:
=INDEX(IFNA(TEXT(A1:A, "00-")&
TEXT(REGEXEXTRACT(B1:B&"", "\d+"), "00")&
IFERROR(REGEXEXTRACT(B1:B, "\D+"))))
Try:
=IF(ISNUMBER(A2), TEXT(A2,"00"), TEXT(LEFT(A2,LEN(A2)-1),"00")&RIGHT(A2))&"-"&IF(ISNUMBER(B2), TEXT(B2,"00"), TEXT(LEFT(B2,LEN(B2)-1),"00")&RIGHT(B2))
And just paste it in every cell in column C

Combine 2 REGEXREPLACE Formulas Into One

In cell C5, I have a date with dashes ---> 01-31-2013
I just need to remove the dashes, extract only the first 4 digits in the date (in this case, 0131), and append 'Efisd' at the BEGINNING of the string.
So, the end result should look like this ---> Efisd0131
So far, I've been able to remove the dashes, and extract the first 4 digits of the date. But, I can't seem to put append 'Efisd' to the beginning and put it all together into one formula.
Does anyone know how to do this? Thanks for your help.
Here's the sample spreadsheet that you can edit
From just the input date you can get it done with this:
="Efisd"&left(substitute(B5,"-",""),4)
It substitutes the dashes for blanks, gets the left 4 characters, and ads Efisd to the front.
If anyone wants the arrayformula version of this, here it is below. Put formula in very top cell in column, edit the header in between quotes, and change cell values to fit your spreadsheet.
={"Your Header";arrayformula(iferror(if(len(M2:M),"Efisd"&left(substitute(M2:M,"-",""),4),""),))}

Get data between number two and three delimiter

I have a large list of people where each person has a line like this.
Bill Gates, IT Manager, Microsoft, <https://www.linkedin.com/in/williamhgates>
I want to extract the company name in a specific cell. In this example, it would be Microsoft, which is between the second and third delimiters (in this case, the delimiter is ", "). How can I do this?
Right now I'm using the split method (=SPLIT(A2, ", ",false)). But it gives me four different cells with information. I would like a command only to output the company in one cell. Can anyone help? I have tried different things, but I can't seem to find anything that works.
Maybe some regex can do it, but I'm not into regex.
Short answer
Use INDEX and SPLIT to get the value between two separators. Example
=INDEX(SPLIT(A1,", ",FALSE),2)
Explation
SPLIT returns an 1 x n array.
The first argument of INDEX could be a range or an array.
The second and third arguments of INDEX are optional. If the first parameter is an array that has only one row or one column, it will assume that the second argument corresponds to the larger side of the array, so there is no need to use the third argument.
A bit nasty, but this formula works, assuming data in cell D3.
=MID(D3,FIND(",",D3,FIND(",",D3)+1)+2,FIND(",",D3,FIND(",",D3,FIND(",",D3)+1)+1)-FIND(",",D3,FIND(",",D3)+1)-2)
Broken down, this is what it does:
Take the Mid point of D3 =MID(D3
starting two characters after the 2nd comma FIND(",",D3,FIND(",",D3)+1)+2
and the number of characters between the 2nd and 3rd comma, excluding spaces FIND(",",D3,FIND(",",D3,FIND(",",D3)+1)+1)-FIND(",",D3,FIND(",",D3)+1)-2)
I'll add my favourite ArratFormula, which you could use to expand list automatically without draggind formula down. Assumptions:
you have list with data in range "A1:A20"
all data have same sintax "...,Company Name, <..."
In this case you could use Arrayformula, pasted in cell B1:
=ArrayFormula(REGEXEXTRACT(A1:A20,", ([^,]+), <"))
If your data doest's always look like "...,Company Name, <..." or you wish to get different ounput, use this formula in cell B1:
=QUERY(QUERY(TRANSPOSE(SPLIT(JOIN(", ",A1:A20),", ",0)),"offset 2"),"skipping 4")
in this formula:
change 2 in offset 2 to 0, 1, 2, 3 to get name, position, company, link
in skipping 4 4 is a number of items.
Number of items can be counted by formula:
=len(A1)-len(SUBSTITUTE(A1,",",""))+1
and final formula is:
=QUERY(QUERY(TRANSPOSE(SPLIT(JOIN(", ",A1:A20),", ",0)),"offset 2"),
"skipping "&len(A1)-len(SUBSTITUTE(A1,",",""))+1)

Split function treating dashes oddly

Why does =SPLIT("1,2-5,4", ",")
equal
1 42040 4
instead of
1 2-5 4 ?
I have all of the cells formatted at plain text.
Regextract should give you the desired output. Try:
=ArrayFormula(regexextract("1,2-5,4", {"^(\d+),",",(.+),",",(\d+)$"}))
To complement JPV's answer.
You can use:
=REGEXEXTRACT(A1,"(.*?),(.*?),(.*)")
which is "hard-coded" to splitting exactly 3 elements (as JPV's is). To give more flexibility, you can use something like:
=REGEXEXTRACT(A1&REPT(",",10),REPT("(.*?),",10))
which is limited to a maximum of 10 elements (that number can be changed to suit). However, it will output an array that is always that maximum number of elements long (padded out with blank cells). You could use QUERY or FILTER to filter out those blank cells - the formula will become a little convoluted.
Alternatively, you can "code" your string such that automatic date coercion is avoided, and then "uncode" it after the SPLIT:
=ArrayFormula(SUBSTITUTE(SPLIT(SUBSTITUTE(A1,"-","x"),","),"x","-"))
With 1,2-5,4 in a cell this can be split as required with Data > Split text into columns... .

Count cells that contain any text

I want to count the cells that contain anything within a range.
Any cell that contain text, or numbers or something else should do a plus one in my result-cell.
I found this function,
countif(range; criteria)
but this doesn't work for me, because I don't know what to type in the criteria. How can I do this?
You can pass "<>" (including the quotes) as the parameter for criteria. This basically says, as long as its not empty/blank, count it. I believe this is what you want.
=COUNTIF(A1:A10, "<>")
Otherwise you can use CountA as Scott suggests
COUNTIF function will only count cells that contain numbers in your specified range.
COUNTA(range) will count all values in the list of arguments. Text entries and numbers are counted, even when they contain an empty string of length 0.
Example:
Function in A7
=COUNTA(A1:A6)
Range:
A1 a
A2 b
A3 banana
A4 42
A5
A6
A7 4 -> result
Google spreadsheet function list contains a list of all available functions for future reference https://support.google.com/drive/table/25273?hl=en.
The criterium should be "?*" and not "<>" because the latter will also count formulas that contain empty results, like ""
So the simplest formula would be
=COUNTIF(Range,"?*")
Sample file
Note:
Tried to find the formula for counting non-blank cells (="" is a blank cell) without a need to use data twice. The solution for goolge-spreadhseet: =ARRAYFORMULA(SUM(IFERROR(IF(data="",0,1),1))). For excel ={SUM(IFERROR(IF(data="",0,1),1))} should work (press Ctrl+Shift+Enter in the formula).
If you have cells with something like ="" and don't want to count them, you have to subtract number of empty cells from total number of cell by formula like
=row(G101)-row(G4)+1-countblank(G4:G101)
In case of 2-dimensional array it would be
=(row(G101)-row(A4)+1)*(column(G101)-column(A4)+1)-countblank(A4:G101)
Tested at google docs.
COUNTIF function can count cell which specific condition
where as COUNTA will count all cell which contain any value
Example: Function in A7: =COUNTA(A1:A6)
Range:
A1| a
A2| b
A3| banana
A4| 42
A5|
A6|
A7| 4 (result)
This works.
=ArrayFormula(SUM(IF(ISTEXT(put-your-range-of-text-mixed-with-anything-here),1,0),1))
IsText(range) looks at your data and returns True for every cell that is text and false for every one that is not. I think these are returned into a data table/array. See step 4.
If(IsText(range),1,0) takes the True/False values from the array/table returned by IsText in step 1, and translates the Trues into 1's and the Falses into 0's, as true integers, not strings.
Sum(range) then totals the 1's (Trues/Cells that are entirely text) and ignores the 0's (Falses/Cells not entirely text).
For some reason, ArrayFormula is needed to return the sum of all cells back into one cell, rather than returning the sum of all cells into a table of equal size. Idk. Would appreciate it if someone knowledgable could please add to this.
Bon chance.
to count any cells that has anything in it (including any text or number values, and also formulas that have text or numeric or blank results), then use:
=COUNTIF(A1:A10, "<>")
or
=COUNTA(A1:A10)
to count only cells that have a value that is NOT blank (including text or numeric values, or formulas that have numeric or text values, but NOT including formulas that have blank results) ie: cell value is longer than zero characters, then use:
=SUMPRODUCT(--(LEN(A1:A10)>0))
or
=COUNTA(FILTER(A1:A10, A1:A10 <> ""))
to count only cells that have a text (alphanumeric) value, then use:
=COUNTIF(A1:A10,"?*")
to count only cells that have a numeric value, then use:
=COUNT(A1:A10)
to count any cells that are blank (including cells that have no value, and cells where the formula result is blank), then use:
=COUNTBLANK(A1:A10)

Resources