How to count number of cells whose contents start with 0? - excel

I need to count how many cells are in a column, but all the content of the cells are id numbers that start with 0. For example, a column of numbers say A1-A3 looks like:
0253980
0253980
0250137
The answer should be "3" but =COUNT(A1:A3) produces "0". This is because the id numbers commence 0. I do not want to convert the numbers because they will be part of other queries later where people need to copy and paste thousands of id numbers into a program which will not work if the 0 is removed.
Is is possible to do a count on these cells?

In Excel what look like numbers are text strings when they start 0 (in general, though numbers may be displayed as preceded with one or more zeros through formatting - all credit to #chris neilsen for reminding me of that!), since Excel automatically strips leading zeros from numeric values. =COUNT:
counts the number of cells that contain numbers, and counts numbers within the list of arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array of numbers.
so is not suitable for text strings. However =COUNTA:
Counts the number of cells that are not empty and the values within the list of arguments. Use COUNTA to count the number of cells that contain data in a range or array.
Hence fortunately the solution is very simply to substitute one function for the other and :
=COUNTA(A1:A3)

Related

Incrementing multiple sequence of numbers in single excel column

I wanted to run multiple sequences of numbers in a single column in excel sheet. For example, this is how a sample output should look like :
As you can see, there are two separate sequences of numbers that are running in single column. One starts from "1" and another starts from "100". What formula can I write in excel such that excel leaves a gap of two rows after "1" and "2" and continues to "3" and "4" and so on.
In this example, I have shown two sequences of numbers which are running in a single column, how can I extend that for 3 or 4 sequences etc.
Here is a draft of how it might look. Basically taking the row number and looking up the corresponding start value, but subtracting out the terms belonging to the other series (two in this case) and subtracting out the rows before it in the current iteration of the series:
=INDEX(A$2:A$4,MATCH(MOD(ROW()-2,9),C$2:C$4))+ROW()-2
-QUOTIENT(ROW()-2,9)*SUMPRODUCT(B$2:B$4*((ROW(B$2:B$4)-1)<>MATCH(MOD(ROW()-2,9),C$2:C$4)))
-INDEX(C$2:C$4,MATCH(MOD(ROW()-2,9),C$2:C$4))
Can be developed into a spill formula in O365 and tidied up removing the helper column and the hard-coded '9' and using Sequence and Let.
So the whole thing in O365 would be
=LET(startRange,A2:A4,
countRange,B2:B4,
cumTotal,MMULT(IF(ROW(countRange)>TRANSPOSE(ROW(countRange)),1,0),countRange),
rowSeq,SEQUENCE(100,1,0),
totCount,SUM(countRange),
modRow,MOD(rowSeq,totCount),
series,MATCH(modRow,cumTotal),
startValue,INDEX(startRange,series),
countForSeries,INDEX(countRange,series),
quotient,QUOTIENT(rowSeq,totCount),
subtract1,quotient*(totCount-countForSeries),
subtract2,INDEX(cumTotal,series),
startValue+rowSeq-subtract1-subtract2)

Excel: INDEX MATCH with partial number

I have a large table of 12 digit numbers and associated info
I have a small list of 10 and 11 digit numbers (the first and/or last digits were cut off) - I'm attempting to cross these two lists to identify the items on the small list
normally, I'd use an index match to bring the associated info out of the table into the list, but because today I have only partial numbers in my list, I can't get the formula to work
I've seen other examples here that search for partial text strings contained within a range, but I haven't been able to adapt those formulas to my data. wildcards don't seem to work with numbers.
Many thanks for your input, and apologies in advance if I failed to find an existing solution on the site.
To match partial numbers inside a number range, like you do with strings, you can use an array formula with INDEX/MATCH, by composing a temporary array that converts the numbers into strings.
Say column A is your 12 digit numbers column, and you want to match the sequence 1234567890 and retrieve the value from column B, This CSE formula works:
=INDEX($B$2:$B$9999, MATCH("*1234567890*",""&$A$2:$A$9999,0))
CtrlShiftEnter
Although you can use full columns A:A and B:B, this should be avoided as much as possible with array formulas, because they're slow. Full columns mean computing and operating arrays of more than a million entries, so avoid it. Also note the "expensive" conversion from numbers to strings (all numbers in the $A$2:$A$9999 are converted to strings here).
To use a cell reference, say D2, instead of the harcoded 1234567890, the formula should be used like this:
=INDEX($B$2:$B$9999,MATCH("*"&D2&"*",""&$A$2:$A$9999,0))

Check for one, two or three digits in a VLOOKUP

I have around 30 numbers which are either 1, 2 or 3 digits which are codes. These codes are attached in front of other numbers. I want to know what code is in front of a number, for example for the number 35467036 the first two digits matches with the code 35. So I want the output for that to be 1.5.
This is my current setup, I have a table with all the codes followed by the output in the next column. If all the codes were three digits long I could just do this =VLOOKUP((LEFT(E6,3)&"*"),D1:E3,2,FALSE) but they are unfortunately not.
I have also tried using nested IF statements but I can only go so far as 7 levels.
Will this only be possible in VBS or is there anther way?
Edit:
The code column is formatted to text. If I enter the value 3 into LEFT it does not work for two digits. Is there anyway I can make it work for 1, 2 and 3 digit codes? Also the codes do not overlap, for example, there isn't going to be 96 and 965 in the code table.
Seven nested IFs as a limit points to a very old version of Excel. You may want to consider upgrading to a version that is still supported in this millennium.
But your main problem is that the data type of your lookup value is text, because you concatenate a string with a wildcard. Whereas your Lookup Table's first column is probably made up of numbers.
In order to solve this you will need to add a Text column to your lookup table that represents the numeric value as a text value.
IF you want to use Vlookup, that helper column will need to be the first column of your lookup range.
You can use an Index/Match instead of Vlookup to be independent of the column order, as this screenshot shows:
Column H shows the formula that has been applied in column G.
Edit:
According to the screenshot you posted, you want to look up from the table in columns E to F and this table only has the short codes. Therefore, it makes no sense to add a wildcard to the lookup value. You just need to extract the value you want to use for the lookup.
If you want to lookup only two digits, then you need to extract only two digits. Adding a wildcard does nothing to remove the third digit.
In the screenshot below, a helper column feeds the LEFT() function the number of characters to extract, then uses that value in the VLookup.
=VLOOKUP(LEFT(A1,B1),$E$1:$F$5,2,FALSE)
=INDEX($G$2:$G$5,
SMALL(
IF(LEFT(A1,3)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,2)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,1)*1=$F$2:$F$5,ROW($G$2:$G$5)-1))),1))
=INDEX(LookupValues,Small(ArrayOfRowsFromIfStatements,FirstRow))
This is an array formula so you will need to use Ctrl+Shift+Enter while still in the formula bar.
We use If to build an array of Row numbers where the conditions match or return FALSE if not. The Small function then returns the smallest result in the array which will be the first row where conditions match.
We then index the results returning that row number (-1 deducted from rows to offset the headers).
If your numbers in column A are always 6 digits + the code length you can use this:
=VLOOKUP(--LEFT(A1,LEN(A1)-6),E2:F5,2,FALSE)

Is there an Excel function to count occurrences of a certain characters in a cell?

A client has an Excel file that needs to have some names scrubbed. In particular, we're trying to isolate suffixes on names (e.g., Jr., Sr., III, etc.) Names are ALWAYS formatted LastName, FirstName, Suffix in the cell, and I am trying to count the number of commas in a cell. If the cell has more than one comma in it, I can identify that cell as having a name suffix.
However, all of the COUNT functions in Excel count instances of CELLS, not characters within cells. Is there a function that counts occurrences of specific characters in a cell and returns that count?
You can get the number of characters in the cell and then compare that to the number of characters in the cell if you substituted out all the commas with empty spaces:
=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))
This is also a neat way to get word counts in excel by counting the number of spaces.
There may not be much point in counting commas because if you know there will always be two at most you might jump to:
=IFERROR(REPLACE(A1,FIND(",",A1,FIND(" ",A1)+1),99,""),A1)

Trying to find out how many times numbers come out in a series

I have an excel spreadsheet with number series and I want to count how many times a particular number shows up (i.e. 4)
Attached is a screenprint
!(http://i.imgur.com/kP4EZXv.jpg)
I looked for samples but no one seems to be trying to do the same thing.
Thanks in advance.
Lenny
If your array is in A1:A4, and you want to count the number of times "1" occurs, you would use:
=COUNTIF(A1:A4, "1")
I put random numbers between 0 and 100 in a1 through e5, using =RANDBETWEEN(0,100).
In another column, starting in G6, I put the numbers 1 through 100. Then in H5 I placed the formula =COUNTIF($A$1:$E$5,G6) and filled down.
It kept a count of how many times each number occurred. And every time I entered a new number, the array of numbers would update and the counts would change.
So it looks like your data is all in one column, A1:A24 all two digit numbers (with leading zeroes if required) and with numbers not repeated within individual cells, in which case you can use COUNTIF with a wildcard, e.g. to count "04" try
=COUNTIF(A$1:A$24,"*04*")
or if you want the criteria as a cell value put 4 or 21 or whatever in C2 and use
=COUNTIF(A$1:A$24,"*"&TEXT(C2,"00")&"*")

Resources