Is there a formula to count the number of numerical values that are separated by a comma in a single cell?
http://support.microsoft.com/en-us/kb/187667
Assuming string in A1:A1... but you can alter to just be a cell or a range...
=SUM(LEN(A1:A1)-LEN(SUBSTITUTE(A1:A1,",","")))/LEN(",")+1
This can be done easily by searching the finding the number of commas in the cell and adding 1.
If the cell you want to search is A1 then use this:
=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1
Related
I have a range/list with values per row. Some of the rows are blank.
I want to name the range, and the range should reach the last value (nonblank cell).
So if any cells below the range that become populated, then the range must expand to those cells, even if there are blanks between, like in scenario 2.
Do anyone have a suggestion to how to solve this?
Try below formula which work both for number and text strings.
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(IF(Sheet1!A:A<>"",ROW(Sheet1!A:A),0)))
If you are on Excel-365 then try-
=Sheet1!A2:INDEX(Sheet1!A:A,MAX(FILTER(ROW(Sheet1!A:A),Sheet1!A:A<>"")))
If the non-blank entries in that column are numeric, you can use:
$M$5:INDEX($M:$M,MATCH(88^88,$M:$M))
where 88^88 is assumed to be larger than any numeric within the range.
If the non-blank entries in that column are non-numeric, and none of the blank entries are in fact null strings (""), you can use:
$M$5:INDEX($M:$M,MATCH("Ω",$M:$M))
I have a comma separated value in A2 and same numbers in different cells B1, C1, D1.... I want to match them from comma separated value and find out the count in B2, C2, D2. Please see the image attached you will get the context.
Can we achieve this by formula or macro in excel?
Tried formula:
=LEN(TRIM($A$2))-LEN(SUBSTITUTE(TRIM($A$2),C1,","""))
Also, I have two data sets where I will be using this formula to find out the count of number from comma-separated value and based on count I want the repeated ones to come in a different cell please refer the image for better understanding.
Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace ! in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma , with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE and FALSE, then SUM up all TRUE which will give the count of the look up value.
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,.
The formula in Cell C2 is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6 is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0 count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8 is concatenating all values from Range C6:K6 and remove the last comma , from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)
The following worked for me, give it a try:
Formula in B2:
=(LEN(","&SUBSTITUTE($A$2,",",",,")&",")-LEN(SUBSTITUTE(","&SUBSTITUTE($A$2,",",",,")&",",","&B$1&",","")))/LEN(","&B$1&",")
Drag right...
A simpler way of doing it is to simply calculate the difference in the length of the string minus the length of the string when replacing the value searched by nothing and dividing by the length of the string searched
The formula would be:
=(LEN($A$1)+1-LEN(SUBSTITUTE($A$1&",",B1&",","")))/LEN(B1&",")
There is a much simpler solution:
=COUNTIF(SPLIT($A$2, ","), B1)
How do I get the desired_output for a given input column containing comma-separated single numeric values as shown in the picture?
Thanks for your help!
Assuming you have your comma-separated values in cell A1, the following array formula will add all such values:
=SUM((TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",255)),1+(ROW(A1:A999)-1)*255,255)) & "0")/10)
To properly return the formula, you need to press CONTROL+SHIFT+ENTER, instead of just the usual ENTER.
I have a table in which one column occasionally contains a sequence of numbers separated by commas (Units). I'd like to find a script that will count the amount of values in that cell (Values), then divide the adjacent cell by that amount, ultimately replacing the value of that cell (NeedResult, replacing Values).
I've played around with formulas, but my VBA skills are rudimentary... Any help mucho appreciated!
table image here
Unless you really want it, I'm not sure you need a VBA solution for this. The calculation can be done using Excel's formulas: simply subtract the length of the string from the length of it with commas removed. Your cell formula could look something like this:
=C3/(LEN(B3)-LEN(SUBSTITUTE(B3,",",""))+1)
Split the first cell value on the commas and adjust the ubound dimension of the resulting array.
dim i as long
i = ubound(split(range("b2").value, chr(44))) + 1
range("d2") = cdbl(range("c2").value / i)
Without the compiler directive Option Base 1, a split array is zero-based.
You could use a formula as well
In D2 entered as array formula with Ctrl+Shift+Enter
=IF(ISBLANK(B2),"",C2/COUNT(FILTERXML("<t><s>" & SUBSTITUTE(B2,CHAR(44), "</s><s>") & "</s></t>", "//s")))
I have a column of data in excel that contains cells of just numbers and then cells of two numbers with a delimiter in between. I want to sort by this field but when I do so it puts all the fields with delimiters down at the bottom. I would like them to be sorted by the first number thats before the delimiter. Would there be an easy to do this using sort or another built in feature?
Regular Cell:
123456
Delimited Cell:
123456 | 789012
you could add one additional column and then split delimited cells and sort the new column.
This would be the easiest i guess
Rather than one, big function, let me show you how to split out the first number before the delimiter.
Let's say A1 is 123456 | 789012.
In B1, put the formula =FIND("|",A1). This will be the index of the delimiter, 8, or a #VALUE error if no delimiter is found.
In C1, put the formula =ISERROR(B1). This returns a TRUE if it finds the delimiter, or else a FALSE.
In D1, put the formula =IF(NOT(C1),LEFT(A1,B1-1),""). This returns the string before the delimiter, 123456, including a trailing blank. You may sort on this as a string, if all the numbers have the same number of digits. (Note that string 21 is lexically higher than string 123456.)
If you need to sort the numbers a numbers, then in E1, put the formula =VALUE(D1). Now 21 < 123456.