multiple selection drop down list - excel

I would like to count the number of unique selections from a column that contains multiple selections from a drop down list.
For example, column B3 contains,
Monday, Tuesday, Wednesday
The count function returns a value of 1 instead of 3 - is there any way to count the three days distinctly? Thank you!
Multiple selections from a drop down list was made possible using the VBA code from: https://docs.google.com/document/d/1JU7G_Tna2zPBtcG2TlarxKCTbuinNsg5LwBqzmuJYK8/edit

This solution is contingent on your string values always being separated by a comma (,). It appears that the code you shared in the link will continue to add comas with the addition of each new string, which means this should work for you.
=IF(A1="",0,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1),",",""))+1)
If cell is blank, return 0
Else, Count instances of commas (,) and offset by 1
Edit 1: (Explanation)
Notice the equation has two very similar parts: LEN(TRIM(A1)) & LEN(SUBSTITUTE(TRIM(A1),",","")). The only difference is that one equation uses the Substitute function and the other does not.
Trim will remove leading and lagging spaces
Len returns the character count of your string
Substitute, in this instance, is used to replace (substitute) all commas with a blank string ("")
The difference between the length of the string with commas to the length of the string without commas equals the total commas that are present in the string. Saying to "count the commas" was a little misleading on my part since we are really deducing the number of commas.

Related

Removing 1st character of number before checking if its > 0, combined with indirect function

I would like to use the =indirect() and =value() function together. I am to count how many numbers are > 0 in another sheet, in the rows I:I. In these sheets, the numbers are not formatted as values, and I am not to do this manually.
In addition, for the numbers, they are formatted as
" 123 "
With a space before the number.
I also need to remove the space in front the numbers in order for this to work.
In my current sheet, in cell J1, I have written "I:I". In the cell A3, I have the name of the sheet that I would like to count the numbers from.
My attempt so far:
{=COUNT.IF(INDIRECT("'"&A3&"'!"&$J$1);">0")
However, this just returns values 0. This is because there is a space infront of the numbers. How do I remove this space? I need to implement it in this function
I've edited the post a bit, as I noticed there was a space infront of the numbers
On a worksheet, if your value " 123 " is in cell A1 then you could use a formula like:
=VALUE(TRIM(A1))
...to TRIM the spaces, and convert the string to a numeric VALUE.
Or, in VBA, something like:
myValue = CInt(Trim(myString))
...to Trim the spaces, and Convert to CInt-eger.
Or, in many ad-hoc situations it's easiest to use "Text to Columns" to remove padded spaces (or any other character, really).
More ways to convert text to numbers here and here.
More ways to remove unneeded spaces here and here.

How to replace chars and remove no in Excel cell

I have this content in my cell in Excel 'TS_Bud03A'
I have other cell content with content that should not be touched by bullet no 1 below. For instance cells with P_Har02b
I would like one nested formula for 2 operations
Substitute 'TS_' with 'TVS_'
Remove the last letter after the 2 digit number if one exists
For the first operation I have made this formula
=SUBSTITUTE(K12;"TS_";"TVS_")
It works. But how do I nest another substitute, that will remove the last letter (any case - if it exists) after the 2 digit number?
By combining the 2 answers below I think I almost got it. Like so:
=SUBSTITUTE(REPLACE(LEFT(K15;LEN(K15)--ISNUMBER(RIGHT(K15;1)*1)-1);2;0;"V");"TS_";"TVS_")
But it still changes this P_Bud04a to this PV_Bud04 and this is wrong. The P cells must be untouched.
Any ideas how I can remove the replace that adds V part of the formula I have here in the question?
See if the following works for you:
Formula in B1:
=REPLACE(LEFT(A1,LEN(A1)--ISNUMBER(RIGHT(A1,1)*1)-1),2,0,"V")
REPLACE(<string>,2,0,"V") - Acts like pasting a substring into a string.
LEFT(A1,LEN(A1)-<number> - Our string in the first parameter of REPLACE() has to be either the full length or minus one. That number is still to be determined.
-ISNUMBER(RIGHT(A1,1)*1)-1 - Will check if the last character in A1 is numeric and therfor will return a boolean value TRUE or FALSE. Their equivalent numeric values are 1 and 0. So if TRUE it will return 0, if FALSE, it will return 1.
EDIT: After your comment I understand your data does not always start with TS_, therefor you need to simply swap REPLACE() with SUBSTITUTE(), e.g:
=SUBSTITUTE(LEFT(A1,LEN(A1)--ISNUMBER(RIGHT(A1,1)*1)-1),"TS_","TVS_")
=IF(ISNUMBER(--RIGHT(K12;2));SUBSTITUTE(LEFT(K12;LEN(K12)-2);"TS_";"TVS_");SUBSTITUTE(K12;"TS_";"TVS_"))
I think this is what you need. It first checks if the right last 2 characters are a number (added -- to convert number stored as text to number). Then, if true, remove the last 2 characters and substitute like you mentioned, or, if false substitute according to your formula without removing the last 2 characters.
OK I got it. I just removed the V between quotes, so as to not put any new content into the cell. And it worked.
=SUBSTITUTE(REPLACE(LEFT(K12;LEN(K12)--ISNUMBER(RIGHT(K12;1)*1)-1);2;0;"");"TS_";"TVS_")
Thanks guys

Total occurrences of a single digit from a string of digits across a range of cells in a column

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.

excel functions find pattern of a string in a cell

I have personal ID's in reports I have to find in one cell. Too bad the string in the cell which hides this ID can be anything, the ID can be at the beginning, the end, anywhere, but it is there.
The only thing I know is the pattern "space,letter,letter,number,number,number,number,number,number,space". Jike DB544345
I was looking for the correct word for this "mask", but couldn't find an answer. Thank you for your help.
As the comments are numerous I have created a minimal example that might represent what the OP is dealing with:
A1: 123456789 DB544345 asdfg asdfghjk
A2: creating dummy data is a DB544345 pain
A3: DB5443456 and soething else
parsed a copy of that in ColumnB with Text To Columns (with space as the delimiter) then applied:
=IFERROR(IF(AND(LEN(B1)=8,CODE(LEFT(B1))>64,CODE(LEFT(B1))<91,CODE(MID(B1,2,1))>64,CODE(MID(B1,2,1))<91,ISNUMBER(RIGHT(B1,6)*1),RIGHT(B1,6)*1>99999),B1,""),"")
to K1, copied this across to P1 and then K1:P1 down.
A concise "built-in function only" solution to a problem such as this requires a bit of tinkering as many attempts will dead-end or need workarounds due to deficiencies and quirks in the built-in Excel formulas. I much prefer single cell formulas because they minimally affect the general spreadsheet structure. However, due to the limitations listed above, complex single cell solutions often come at the cost of being rather long and cumbersome (this answer is somehow still only two lines on my formula bar in Excel). I came back to your question and cobbled together a formula that can (as far as I have tested) extract the first occurrence of this pattern with a single cell formula. This is an array formula (Ctrl+Shift+Enter instead of Enter) that assumes your data is in A2. This rough formula returns the first 8 characters if no match is found and throws #REF if the string is shorter than 10 characters.
=MID(A2,MIN(IF(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9))),1)=" ",IF(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+9,1)=" ",IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+1,1))>64,IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+1,1))<91,IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+2,1))>64,IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+2,1))<91,IF(IFERROR(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+3,6)*1>99999,FALSE),ROW(INDIRECT("A1:A"&(LEN(A2)-9)))))))))))+1,8)
Let me try to break this down at least on a high level. We are splitting the main text into every possible ten character chunk so that we can test each one using the suggestion of #pnuts to verify the Unicode values of the first two characters and run an ISNUMBER check on the rest of the string. This first block recurs throughout my formula. It generates a list of numbers from 1 to n-9 where n is the length of our main text string.
ROW(INDIRECT("A1:A"&(LEN(A2)-9)))
Let's assume our string is 40 characters long and replace the above formula with {1...31}. Using this number sequence generation we can check if characters 1 to 31 are spaces:
IF(MID(A2,{1...31},1)=" "
Then we can check if characters 10 to 40 are spaces:
IF(MID(A2,{1...31}+9,1)=" "
Then we can check if characters 2 to 32 are capital letters:
IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+1,1))>64,
IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+1,1))<91
Then we can check if characters 3 to 33 are capital letters:
IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+2,1))>64,
IF(CODE(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+2,1))<91
Then we can check if the strings of characters 4 to 9, 5 to 10, ..., 33 to 38, 34 to 39 are six-digit numbers:
IF(IFERROR(MID(A2,ROW(INDIRECT("A1:A"&(LEN(A2)-9)))+3,6)*1>99999,FALSE)
If all conditions are TRUE, that 10 digit chunk test will return the index of its first character in the string via another instance of the original array {1...31}. Otherwise it returns nothing. We take the Min of all return indexes and then use the Mid function to grab the 8 digit string determined by the aforementioned minimum index:
=MID(A2,MIN(matching index list)+1,8)
I think this will work, if we assume that the SPACE at the beginning and end are merely to differentiate the ID from the rest of the string; hence would not be present if the ID were at the beginning or end of the string. This formula is case insensitive. If case sensitivity is required, we could do character code comparisons.
=LOOKUP(2,1/((LEFT(myArr,2)>="AA")*(LEFT(myArr,2)<="ZZ")*(LEN(myArr)=8)*ISNUMBER(-RIGHT(myArr,6))),myArr)
Where myArr refers to:
=TRIM(MID(SUBSTITUTE(TRIM(Sheet2!A1)," ",REPT(" ",99)),(ROW(INDIRECT("1:10"))-1)*99+1,99))
If myArr is initially defined with the cursor in B1, referring to A1 as shown, it will adjust to refer to the cell one column to the left of the cell in which the Name appears.
The 10 in 1:10 is the maximum number of words in the string -- can be adjusted if required.

Excel Test Length of 1 field and divide if len>200

I have column B that I need to test the length to see if it is longer than 200 characters. If it is longer than 200 characters, I need it to go from right to left and find the occurrence of the semicolon ";" and split the field from the right of the semicolon into column C. Can this be done? Before I was having to do this with 4 columns and have reduced it to one column. Please advise to the best formula to do this.
=IF(LEN(B1)>200,MID(B1,SEARCH("#",SUBSTITUTE(B1,";","#",LEN(B1)-LEN(SUBSTITUTE(B1,";",""))))+1,LEN(B1)),"")
Explanation:
Remove all instances of the delimiter: SUBSTITUTE(B1,";","")
Subtract the length of (1) from the length of the entire string to get the number of occurrences of the delimiter: LEN(B1)-LEN([1])
Substitute the last occurrence of the delimiter with an #: SUBSTITUTE(B1,";","#",[2])
Find the location of the #: SEARCH("#",[3])
Get the substring of everything to the right of the # location: MID(B1, [4] +1,LEN(B1))
Add if condition to only process strings of length > 200: =IF(LEN(B1)>200,[5],"")
I searched the web for formulas for this and concluded that you either need a lot of nesting and a difficult to follow formula or a VBA function. I would suggest using a VBA function such as the one I have written below (FindLast) within a simple formula. Let me know if you need instructions on how to create this VBA formula:
Function FindLast(find_text As String, within_text As Range) As Double
Dim i As Integer
i = Len(within_text.Value) ' start at last character and work back
Do While Mid(within_text.Value, i, 1) <> find_text
i = i - 1
Loop
FindLast = i
End Function
You will then be able to use FindLast within a formula such as the below in C1:
=IF(LEN(B1)>200,MID(B1,FindLast(";",B1)+1,500),"")
UPDATE
The 500 in the above is just a long number I picked to mean the rest of the cell. If there may be more than 500 characters after the final ; then use a larger number. Unfortunately I don't think the MID function allows you to specify that you want to return the rest of the cell. I have put to return nothing if B1 is not >200 characters, let me know if this is not the requirement.

Resources