I have two lists as follows, Column A and Column D:
I would like to find all cells in Column A that do not contain a value from Column D.
For instance, A1 should be 0 because it contains the values 'a', 'b', 'c' and 'd' - all of which are in Column D.
A2 should be 1 because it contains the value 'h' - which is not in Column D.
My formula so far is very simple:
=COUNTIF(D1:D7,"*"&$A1&"*")
I'm guessing I could split the values in Column A to check, but am not too sure how.
I would like to avoid any VBA if possible.
Your question is not entirely clear to me, so far as what you want for results under different circumstances.
Your formula will return an array of values, so you need to account for that. The array consists of a 1 or a 0 depending on whether the character matches a letter in the D1:D7 range.
If you want to return the number of letters in your column "A" item that do NOT match an entry in Column "D", then try:
=LEN(A1)-SUMPRODUCT(COUNTIF(A1,"*"&$D$1:$D$7&"*"))
The SUMPRODUCT functions sums the array that the COUNTIF function is returning.
If you want something else, you will need to be more specific.
Cross-tabular layout
Using your logic, just with different layout of the data, you can achieve this:
Formula for B4 is: =COUNTIF(B$3;"*"&$A4&"*")
Formula for B1 is: =B2-SUM(B4:B10)
This is more along the lines of a comment, but I don't have enough reputation yet for comments.
The accepted answer from #ronrosenfeld will not work if the string in Column A contains repeated characters from the list in Column D. For example, if A1 contains "abca," it will return 1 rather than 0 because the array entry for "a" is 1 rather than 2 (it can only be 0 or 1).
So be aware that it only works if the letters are not repeated.
I cobbled a formula together based on some array magic I found by #ronrosenfeld here. (It seems so appropriate that Ron already got credit for answering this question, as my answer is a modification of another of his.)
The following formula works for any length of string in Column A and for any combination of letters including duplicates. It is entered as a regular formula:
=IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1)
You just enter it in B1, then copy it down as far as you like.
It works for strings of any length. If a cell is blank, it returns 1 because there is nothing there that appears in the list. If you want 0 for a blank cell, you can adjust the formula for that situation. Brute force approach:
=if(isblank(a1),0,IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1))
Related
=(Countifs(B:B;”*”;F:F;”<>*1”))
Why doesn't this work?
I want to count all the rows in the sheet, except the ones that has a number that ends with 1 in column F. It just count all the rows, even the ones in column F that ends with 1.
How do I exclude those?
edit
Some more information!
This is a sample of the data:
Could be up to 8000 rows some days. Column B always says "Independent instruction" so I'm using that as a base to count all the rows. Column F contain only numbers, or blank cells (meaning a number will be added later). I still want to count those rows as well (that's blank). It's just the rows that has a number in column F that ends with 1 that I want to exclude!
SUMPRODUCT gives a bit more flexibility for criteria that involve more than straightforward string-matching:
=SUMPRODUCT(--(LEN($B:$B)>0),--(RIGHT($F:$F,1)<>"1"))
The array formula:
{=COUNT(IF((F:F<>"")*(MOD(F:F;10)<>1);F:F))}
will count all non empty cells in the conditions of your question.
Don't forget to press Ctrl+Shift+Enter to place the formula.
Why doesn't this work?
Apart from the fact that you have transcribed it incorrectly (i.e. missing =, and smart quotes ”) the 'F' condition in quotes is a Text value, a formatting issue #BigBen has mentioned in connection with the 'B' values.
You say It just count all the rows so, syntactically corrected, your formula must be working on (a) all 'B's populated (with Text) and (b) all 'F's Numeric. As 1 and "1" are not the same, none of your entries in ColumnF will be excluded by your attempt (none end in "1", though presumably some do end in 1).
#Pspl's A works because its condition (for the 'F's) is based on MOD (applies to Number format values) and #jsheeran's A (my preference) because RIGHT is a string function that returns Text format even from a Number format value.
Put another way, with say 1 in F1, =F1="1" returns FALSE (so =F1<>"1" and =F1<>"*1" return TRUE - that would not suit you) whereas =RIGHT(F1)="1" returns TRUE (or, to suit you, RIGHT(F1)<>"1" returns FALSE).
You can try to use a combination of SUM and IF. Remember to adjust the formula to match your Excel formatting, i.e. replace commas (,) with semicolon (;).
This is an array formula (enter with Ctrl+Shift+Enter)
=SUM(IF(MOD($F$2:$F$25,10)<>1,1,0))
Result (updated with your data set):
When pasting the image into merged cells, the error looks like that:
So you need to make sure the formula is pasted into a single (not merged) cell.
Array formula for values greater than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25>1000),1,0))
Array formula for values less than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25<1000),1,0))
Example:
I have this function:
MATCH(1,(PositionParameter[[#All],[Position Revised]]=$C94)asterisk(PositionParameter[[#All],[Campus Type Short]]=G$3)asterisk(PositionParameter[[#All],[Campus Num Arbitrary]]=G$1),0))
and I can't figure out what it does. I don't know what the asterisks are for. PositionParameter is the name of the worksheet, Position Revised is the name of a column, Campus Type Short is the name of a column, and Campus Num Arbitrary is the name of a column. There is suppose to be an asterisk between the first PositionParameter() and the second PositionParameter(). There is supposed to be another asterisk between the second PositionParameter() and the third PositionParameter(), but it is rendered as an italic. I took the asterisk out and spelled it out. The tooltip tells me this is suppose to return some sort of array, but I can't figure out its components. Can someone explain the asterisks to me? I would appreciate it.
Thanks,
Howard Hong
Your formula returns a single value - the relative position of the first row in the data where all three conditions are met.
It works like this:
Each of these three conditional statements:
PositionParameter[[#All],[Position Revised]]=$C94
PositionParameter[[#All],[Campus Type Short]]=G$3
PositionParameter[[#All],[Campus Num Arbitrary]]=G$1
.....returns an array of TRUE/FALSE values. Multiplying these three arrays together produces a single array of 1/0 values, 1 when all conditions are met in a row, 0 otherwise. This array forms the "lookup array" of the MATCH function
The "lookup value" is 1 so that value is looked up in the lookup array and the result of the MATCH function is the position of the first 1, which corresponds to the first row where all conditions are satisfied.
If there are no rows which meet all three conditions then the result is #N/A
Note that the zero at the end is the third parameter of the MATCH function - zero menas that an exact match must be found.
This is an "array formula" which needs to be confirmed with CTRL+SHIFT+ENTER
Often you would use this in conjunction with INDEX function to return a value from another column in the first row where conditions are satisfied, e.g. using normal cell references
=INDEX(A:A,MATCH(1,(B:B="x")*(C:C="y"),0))
That formula will return the value from column A in the first row where the two specified conditions are met (col B = "x"and col C = "y")
Well, asterisk could be a multiplication symbol or it could be a wildcard in Match. By the looks of the placement, I'd say it's multiplying data from an array or table.
And, um... I don't know what the asterisks are for but I took the asterisk out and spelled it out? Why would you do that? Was it working before you changed it? Where did you find this formula?
Please read [mcve]. Without sample data or other information about the purpose of the formula, I will take a wild guess:
Paste this into the cell:
=MATCH(1,(PositionParameter[[#All],[Position Revised]]=$C94)*(PositionParameter[[#All],[Campus Type Short]]=G$3)*(PositionParameter[[#All],[Campus Num Arbitrary]]=G$1),0))
. . . and assuming it's supposed to be an array, instead of hitting Enter on that cell:
hit: Ctrl+Shift+Enter to create an array formula.
Besides the link above, here is some other reading & practice for you:
Create an array formula
MATCH function
I think certains applications replace certain symbols (that aren't allowed in the application] with words when copying and pasting from Excel to them, but without more information about what happened, I can't say for sure what happened.
Assuming that the * are real and that the formula is entered as an array formula then it should return an array of 0s and 1s.
The formula is looking for Position Revised=C94 AND Campus Type Short =G3 AND Campus Num Arbitrary = G1
It will return a 1 for each row that matches all these conditions and a 0 for each row that does not.
If no rows match the conditions it will return #N/A
I am currently drawing up a spreadsheet that will automatically remove duplicates and alphabetize a list:
I am using the COUNTIF() function in column G to create a sort order and then VLOOKUP() to find the sort in column J.
The problem I am having is that I can't seem to get my SortOrder column to function properly. At the moment it creates an index for two number 1's meaning the cell highlighted in yellow is missed out and the last entry in the sorted list is null:
If anyone can find and rectify this mistake for me I'll be very grateful as it has been driving me insane all day! Many thanks.
I'll provide my usual method for doing an automatic pulling-in of raw data into a sorted, duplicate-removed list:
Assume raw data is in column A. In column B, use this formula to increase the counter each time the row shows a non-duplicate item in column A. Hardcord B2 to be "1", and use this formula in B3 and drag down.
=if(iserror(match(A3,$A$2:A2,0)),B2+1,B2)
This takes advantage of the fact that when we refer to this row counter in our revised list, we will use the match function, which only checks for the first matching number. Then say you want your new list of data on column D (usually I do this for display purposes, so either 'group-out' [hide] columns that form the formulas, or do this on another tab). You can avoid this step, but if you are already using helper columns I usually do each step in a different column - easier to document. In column C, starting in C3 [C2 hardcoded to 1] and drag down, just have a simple counter, which error-checks to the stop at the end of your list:
=if(C2<max(B:B),C2+1," ")
Then in column D, starting at D2 and dragged down:
=iferror(index(A:A,match(C2,B:B,0)),"")
The index function is like half of the vlookup function - it pulls the result out of a given array, when you provide it with a row number. The match function is like the other half of the vlookup function - it provides you with the row number where an item appears in a given array.
Hope this helps you in the future as well.
The actual reason that this is going wrong as implied by Jeeped's comment is that you can't meaningfully compare a string to a number unless you do a conversion because they are stored differently. So COUNTIF counts numbers and text separately.
20212 will give a count of 1 because it is the only (or lowest) number.
CS10Z002 will give a count of 1 because it is the first text string in alphabetical order.
Another approach is to add the count of numbers to the count if the current cell contains text:-
=COUNTIF(INDIRECT("$D$2:$D$"&$F$3),"<="&D2)+ISTEXT(D2)*COUNT(INDIRECT("$D$2:$D$"&$F$3))
It's easier to show the result of three different conversions with some test data:-
(0) No conversion - just use COUNTIF
=COUNTIF(D$2:D$7,"<="&D2)
"999"<"abc"<"def", 999<1000
(1) Count everything as text
=SUMPRODUCT(--(D$2:D$7&""<=D2&""))
"1000"<"999"
(2) Count numbers before text
=COUNTIF(D$2:D$7,"<="&D2)+ISTEXT(D2)*COUNT(D$2:D$7)
999<1000<"999"
(3) Count everything as text but convert numbers with leading zeroes
=SUMPRODUCT(--(TEXT(D$2:D$7,"000000")<=TEXT(D2,"000000")))
"000999" = "000999", "000999"<"001000"
Sorry if this is lengthy but I want to be as clear as possible. Here is an example so that its easier to understand, then I will lay out the details, finally I will explain what I would like to do.
A picture of my example is at: imgur.com/9uK9So9
I couldn't post a picture because of <10 rep :/
Column A- the "name" portion of it must be exactly 12 characters and the "number" portion must be 5 (not including the '.').
So, cell A1 is "ADAM2_______25.000".
name="ADAM2_______"
number="25.000"
Column B-just the name portion without any extra spaces.
So, cell B2 is "ADAM2"
Column C-same as column B but may be different (the reason I'm doing the comparison)
Column D-the number portion without the trailing 0's.
So, cell D2 is "25"
Column E is where I want the comparison to output something along the lines of true or false.
I know that columns C and D are correct, I am not sure if A and B are though. I want to compare column A with the values in Column C and D but I do not know how to account for the random number of spaces in between the name and number portion in Column A. Also I want to make sure Column B matches column C but that should be pretty easy once the first part is done.
Basically, how to I account for the varying number of spaces/trailing 0s in my comparison?
Mostly I've been using Conditional IF/AND statements. I tried using the CONCATENATE function but it didn't seem to work as I was hoping.
Thanks!
^^EDIT 1
In column E I tried =IF(A2 = (B2+D2),TRUE(),FALSE()) But obviously that will not work. It gives an #VALUE! error.
I tried splitting Column A into 2 more columns using text to columns. This got rid of the trailing 0s and the extra space(s) after the end of the "name" part. From here I think It should be pretty easy with just basic IF statements.
What you want is the string-searching functions - either FIND [case sensitive] or SEARCH [not case sensitive]. These functions look at a given string, and check to see whether a search term is within that string. If it is present, it gives you the character number where the match starts; if it is not present, it gives an error.
So to see if A2 contains the term in B2 as well as the term in D2, you would use:
=if(and(isnumber(search(B2,A2)),isnumber(search(D2,A2))),"BOTH TERMS PRESENT", "AT LEAST 1 TERM NOT PRESENT")
Note that this doesn't compare with column C at all - I can't tell whether you actually are trying to compare that one are not.
Here are my 2 columns
A B
Spain [EMPTY]
France Euros
Spain Euros
In another cell, I would like to write a formula that would write the currency of each country. like if I have:
C1=Spain, C2=France,
I would want to have
D1=Euros, D2=Euros.
I tried it with VLOOKUP, but it gave me
C1=[Empty], C2=Euros
Thank you very much for your time
As others have commented, VLOOKUP will return the first match it finds, thats why you get [EMPTY] for Spain.
You can work around this by adding an intermediate column. Lets assume you insert a column B with formula =IF(C1="","",A1) and copy down for all used rows.
Column D is Spain, France etc
Column E is now =VLOOKUP(D1,B:C,2,0)
IF you can SORT your columns, sort by Column A then by B descending (Z-A) then use the vlookup you're trying to use. THis will put the country with a value 1st so V-Lookup will return a vale instead of empty. When empty is returned, its becuase EVERY single instance of that entry in column A has an empty value. However if the entry in A has Multiple values, it will pick the first from descending order.
So do you have situations in which a entry in column A has multiple values beyond 1 currency and a blank entry?
However this has a pitfall in that the Order now matters so if data is added to this spreadsheet a reorder must occur each time.
I'm more a VBA than formula guy but this (horrible!) array formula will return the first non blank match
in D1 put
=IF(MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))>0,INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))),"no match")
and press Shift - Ctrl - Enter together
how it works
IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)) checks that A1 matches each of A1 to A6, and correspondingly whether B1 to B6 is non-empty.
If both these conditions are TRUE then the row number of these matches is placed in an array, if FALSE the formula returns zero. so the first array id {0,0,3,0,0,0}
If the MAX of this array is not zero then the formula returns this cell position from the B column using INDEX in INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)))
Else there is "no match"
I will shoot this to a formula genius called Barry Houdini to see how much he can shorten it
Enlarged sample (including a true blank result) below
I feel like a fraud here.....don't ask me any VBA questions!
I note that use of MAX actually means that your formula (and chris' amended version) actually gives the last non-blank match. You can also do that with a non-CSE LOOKUP formula, i.e.
=LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)
which will return #N/A if there's no match
for the text "no match" instead then, assuming formula returns text values you can use 2003 compatible
=LOOKUP("zzz",IF({1,0},"No match",LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)))
For first non-blank match you can use INDEX/MATCH in a similar way, i.e.
=INDEX(B$2:B$6,MATCH(1,(B$2:B$6<>"")*(A$2:A$6=C1),0))
confirmed with CTRL+SHIFT+ENTER