I have multiple cells which have number separated by columns and want to count the number of existence of a specific number. How may I count the number. what will be the formula.
I have data like in picture and want to count the existence of 1 or any other number in all highlighted cell. I used the countif formula to count the number 1 but it also counts it for 11 or 12.
If anyone have any Solution.
Thanks
enter image description here
I would try and restructure your data so it's easier to work with. Otherwise, here's a dirty solution:
You could first add a comma before and after all your cells with "," & cell & "," so all numbers are separated by a comma, including the last one. Then use COUNTIF to count numbers, by looking for eg. *,1,* or *,12,*:
Orginal
="," & A1 &","
=COUNTIF([your cell range];"*,1,*")
1,2,10,11,12
,1,2,10,11,12,
4
1,2,10,11,12
,1,2,10,11,12,
1,2,10,11,12
,1,2,10,11,12,
1,2,10,11,12
,1,2,10,11,12,
Related
We need to count how many occurrences of each number are in a cell over a range of cells in the same column and output a tally of the totals for each number. See the attached picture and the desired output in the column next to it. We tried other formulas found online in both excel and open office with no results.
letter Count
Working Count
Try the following formula in D1:
=LEN(TEXTJOIN("",TRUE,A:A,"#"))-LEN(SUBSTITUTE(TEXTJOIN("",TRUE,A:A,"#"),C1,""))
and populate down.
(you will need 2016 or later for TEXTJOIN)
Option 1
Single array formula (ctrl+shift+enter !) which will work for strings with a maximum length of [5] alphanumeric characters (but you can easily modify the formula by adding a few numbers in the hard-coded array constant {1,2,3,4,5}):
{=SUM(N(MID($A$1:$A$500,{1,2,3,4,5},1)=TEXT(C3,"#")))}
You can add some further trickery to let Excel define the array constant, so the formula will work for any length of the string of digits :
{=SUM(N(MID($A$1:$A$500,
COLUMN(INDIRECT("A1:"&CHAR(65+MAX(LEN($A$1:$A$500)))&"1"))
,1)=TEXT(C3,"#")))}
The part in the middle (COLUMN()) creates the {1,2,3,4,5} array. You might have seen other versions of this formula, without the CHAR, which I use to create a reference to e.g. cell E1 (knowing that 65 is the code for "A").
.
Option 2
This array formula (ctrl+shift+enter !) works in all Excel versions, but is not very "elegant" as you have to repeat the key part of the formula as many times as the maximum digits you have in your cells (this example is for max 3 characters):
{=SUM(
N(MID($A$1:$A$500;1;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;2;1)=TEXT(C3;"#"))+
N(MID($A$1:$A$500;3;1)=TEXT(C3;"#")) )}
The character you are counting is in C3. This will work for numbers and letters. If you can have five alphanumeric characters, you have to add two more N(...) parts, and replace the second parameter of the MID function with 4 and 5 respectively.
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")))
Problem: I need a formula to automatically increment when dragging down. Since the 3 strings are joined by concatenating, it doesn't seem to work.
=CONCATENATE("Sheet2!", SUBSTITUTE(ADDRESS(1,MATCH("String to Search For", Sheet2!$13:$13,0),4),1,""),"17")
String 1 is a separate sheet reference (Sheet2!)
String 2 is the column number converted to column letter where string to be searched is found using MATCH, ADDRESS, and SUBSTITUTE. In this case it was column 2 converted to B.
String 3 is the row number that I need information from IF string searched is found
After concatenating these, I need to drag it down 5000 rows and increment String 3 (the row number) but because the reference is concatenated, it will not increment. I've tried everything! Please help!
Try adding a ROWS function, e.g. if you put the first formula in Z2 use this version copied down
=CONCATENATE("Sheet2!", SUBSTITUTE(ADDRESS(1,MATCH("String to Search For", Sheet2!$13:$13,0),4),1,""),"17"+ROWS(Z$2:Z2)-1)
change depending on actual start cell
ROWS function, used this way, will increment by 1 each row and is more "robust" than alternatives using ROW for example
Assuming your formula is in row 2, you could do this:
=CONCATENATE("Sheet2!", SUBSTITUTE(ADDRESS(1,MATCH("String to Search For", Sheet2!$13:$13,0),4),1,""),text(row()+15,"#"))
If your formulas starts on a different row, just change the 15 as needed.
I have 3 names that I want to combine to create something unique - I've used "CONCATENATE", but to no avail.
Example:
Paper (will always be different)
000001 (This will be sequential, the next row will have 000002)
Plastic (will always be different)
Essentially I want to input all three items in different cells and have the fourth cell output the following:
Pa000001Pl
Thank you.
Using & between objects is an alternative way to concatenate in excel:
=LEFT(A1,2) & B1 & LEFT(C1,2)
See http://fiveminutelessons.com/learn-microsoft-excel/extract-text-cell-excel for info on how to extract text from cells. (Examples: LEFT(), RIGHT(), MID(),FIND().
See https://support.office.com/en-za/article/Combine-the-contents-of-multiple-cells-3a86c317-6b91-4f1d-8781-203320aefdce for info on how to combine text from cells.
If you want to keep the 00000's in the number you need to make sure to format the cells containing the numbers as Text.
You could do this using the TEXT() function on the fly:
=LEFT(A1,2) & TEXT(B1,"000000") & LEFT(C1,2)
The six 0's tell Excel to create a number 6 digits long and replace any 0 with a non-zero number from your cell. So if B1 is 1, TEXT(B1,"000000") will convert it to 000001. If B11 is 11, TEXT(B11,"000000") will convert it to 000011.
If you instead want to ensure that the same number of 0's remain in front of your non-zero numbers, you could use the CONCATENATE() function:
=LEFT(A1,2) & CONCATENATE(B1,"00000") & LEFT(C1,2)
This would always insert five 0's in front of whatever number is listed in B1.
With values in A1, B1, and C1, in another cell enter:
=LEFT(A1,2)&TEXT(B1,"00000")&LEFT(C1,2)
This is needed to preserve the leading zeros if those leading zeros are the result of formatting cell B1
Assuming your values are in the 2nd Row
=LEFT(A2,2) & B2 & LEFT(C2,2)
I have a number of 'accounts' for which i would like to create a unique reference code for each. The reference code will be a combination of parts of different cells. So, for example, the reference for the 'account' occupying row 1 would be: cp78925
The cp part is a constant, and will always be the same.
The 789 part are the last three digits of cell A1, which contains a 10 digit code
The 25 part are the first two digits of cell B1, which contains the date on which the account was opened.
So for example:
if A1 = 1123456789, B1 = 25/10/2013 then the unique reference code in C1would be = cp78925
Searches on the internet show ways of separating the contents of cells by blanks (""), /, after letters etc., or making the last 3 digits BOLD/ITALIC, but I cant work out how to get my specific answer.
Thanks a lot in advance. I hope this is clear enough.
you need something like
="CP" & RIGHT(A1,3) & DAY(B1)
="CP" & RIGHT(A1,3) & TEXT(B1,"dd")
Anyway this formula is not going to give you an unique reference if two A1 code ends with the same 3 digits the same day.
1234567890 01/01/2013
3213512890 01/02/2013
Both will return you CP89001
Edit:
As reported by Sam092 (thanks), DAY() return a numeric value, TEXT() is the right function to use
Formula in C1
="CP"&RIGHT(A1,3)&LEFT(TEXT(B1,"DD/MM/YYYY"),2)
EDIT:
I see that you have tagged your question with VBA. You don't need vba for this but still if you want a VBA solution then try this
ThisWorkbook.Sheets("Sheet1").Range("C1").Formula = _
"=""CP""&RIGHT(A1,3)&LEFT(TEXT(B1,""DD/MM/YYYY""),2)"
or
ThisWorkbook.Sheets("Sheet1").Range("C1").Value = Evaluate( _
"=""CP""&RIGHT(A1,3)&LEFT(TEXT(B1,""DD/MM/YYYY""),2)")