Is there a way to check if a text exists and is a unique entry within a column and then get a cells value which is relative to the position of the found cell?
Here is the approach I tried and a more detailed explanation:
I am using this formula to check if a text exists and is a unique entry within the column D.
=COUNTIF(D:D;X1)=1
If that is the case this function returns TRUE.
Is there a way to get the cell's position, which is found by Excel to make the check for the function mentioned above? Moreover I am interested to know if then one can get a relative cell value from the position returned by Excel e.g: 2 columns on the left of the found position.
Do I need a different, maybe nested function or is this only possible with VBA?
What can I do?
=MATCH(D1, X:X, 0) will find the row number of the first D1 in column X, or #N/A if there are none.
=INDEX(V:V, 42) will show the value of cell V42.
Combining this:
=IF(COUNTIF(X:X, D1)=1, INDEX(V:V, MATCH(D1, X:X, 0)), NA())
This should do what you need - if there's a unique match in column X, it shows the corresponding value from column V.
You can take this further by naming the columns, for example:
=IF(COUNTIF(client_email, D1)=1, INDEX(client_name, MATCH(D1, client_email, 0), NA())
This has the upside that you can see you're looking for the client's name if they and only they have a particular email address. And the downside that it's less obvious where on the sheet that data is stored. Swings and roundabouts!
Related
I am trying to create a formula that checks Column A for unique values, then takes that value and checks column B for unique values and orders them sequentially in Column C. Column C is the where the formula goes. It's not in the actual data set.
This is what I want my data set to look like.
For example, I want to find unique Entry Number "123-A. I then want to look within that entry number and find the unique codes in Column B and order them sequentially. The first two are the same, so they both are sequence 1. Then the third row as a new code, "Y09", so it will get sequence 2. Once the next unique entry number is identified, I want to reset the sequential count. Thanks!
So, the first thing we want to do is check if a number has already been allocated. Since there are 2 columns to check, we need to use INDEX MATCH with an Array Condition instead of just a VLOOKUP:
INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0))
These formula are intended for cell C2 - notice how we left the second cell in each Range reference without the $ to lock it in place. This means it will always stop at the row above the formula
If this works, we're done. If it doesn't we get an error - so, we can use IFERROR:
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), ???)
On to replacing those question marks!
Since we don't have a match, we need to find the largest match for the Entry Number, and add 1 for it. If you have Office365 or Office2019, we can just use the MAXIFS function. Otherwise, we will have to use SUMPRODUCT and MAX to get the same result: (If the Entry Number does not exist, this will return 0)
MAXIFS($C$1:$C1, $A$1:$A1, $A2)
SUMPRODUCT(MAX($C$1:$C1 * ($A$1:$A1=$A2)))
Then, Add 1:
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), MAXIFS($C$1:$C1, $A$1:$A1, $A2) + 1)
=IFERROR(INDEX($C$1:$C1, MATCH(1, ($A$1:$A1=$A2)*($B$1:$B1=$B2), 0)), SUMPRODUCT(MAX($C$1:$C1 * ($A$1:$A1=$A2))) + 1)
It appears that your data is already organized/sorted by the column A and B values. If this is the case, we can construct a formula implementing the following rules:
if the adjacent A and B values match the values above them, copy down the C value from above
if the adjacent A value matches the value above it, but the B value does not, then increment the C value from above.
If the A value does not the value above it, then set the C value to 1
In C2 enter 1. In C3 enter:
=IF(AND(A3=A2,B3=B2),C2,IF(A3=A2,C2+1,1))
and copy downward:
if your data is not organized in the same way your picture indicates, then ignore this solution.
On Sheet 1, I have a master list of data, with corresponding attributes. Some data has more than one attribute, some has only one, and there is a possibility of blanks. Attributes can be repeated when assigned to a different name.
I've posted some example data below, so we can all talk about the same cells/names etc.
On Sheet 2, there is much more freeform data input/analysis going on. Users are able to select a 'Name' from a dropdown menu using Data Validation, and are then able to select from the available attributes corresponding to that name, again using a dropdown menu. Names and attributes can appear in any order on Sheet 2.
It is important that all pairings are considered in the second worksheet.
Is it possible to use conditional formatting to highlight the 'Name' field (on Sheet 2) until at least one row exists with all possible pairings? In the example below, you can see that we have forgotten to put any info relating to the fact that Sally is Happy, and consequently 'Sally' has been highlighted to draw attention to the fact that there is some missing information.
Current thoughts:
I already have a list of the attributes that match the corresponding name- this is what drives the dropdown menu on Sheet 2, and is generated in a background sheet when a name is picked on Sheet 2. I can count the non-blank cells in this range to find out the total number of pairs that are required.
I would like to then count the number of non-duplicate attributes that are on rows that have the same Name as the current row, and compare this value.
I'm expecting this to get into the realms of array formulae, but may be wrong...
I'm also expecting array formulae to not work directly with conditional formatting, and to require the use of a 'helper column' to drive the formatting. Let me know if this is incorrect?
Something along the lines of the below (formatted as pseudo-code for readability, but this should be read as a high level description, not actual code)
{Count the 1s in the array(AND(
'Check if it's a name match'
If($D$1:$D$10=[$ACurrent],[set flag to 1],[set flag to 0])
'Check if it's a unique value'
[somehow check array values set at 1 to see if there is a duplicate value in column E, and then set the array value to zero if so])
}
Does this approach make sense, and how would I go about constructing this actual formula?
I don't mind using VBA if required, but would prefer to avoid it if possible (company policy, sorry).
Well, you want to highlight value Sally, Happy if that value does not appear in Sheet2, so you just need a COUNTIFS
COUNTIFS function
I've got this:
I've used a Conditional Formatin Rule based on my own formula. The formula I've used is:
=IF($B2="";IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;"")=0;TRUE;FALSE);IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;$B2)=0;TRUE;FALSE))
There are 2 COUNTIFS, because blank values are possible:
IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;"")=0;TRUE;FALSE) will count how many rows got same name and non blank attributes in Sheet2. If 0, then it will return True and highlight row.
IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;$B2)=0;TRUE;FALSE) will count how many rows got same name and blank attributes. If 0, then it will return True and will highlight
With the initial IF you can blanks or non blanks attributes, just to make sure you count all posibilities of values.
I've uploaded a sample to mi Gdrive in case you want to download and get the formulas autotranslated opening at your PC.
https://drive.google.com/open?id=1Im4LoaK4EIvINBj7tfyEcYk9juWUp7zr
Hope you can adapt this to your needs.
#Foxfire And Burns And Burns helped me to solve my problem - I have modified his formulae slightly, to remove the double COUNTIFS, and to account for rows in the master data where both cells are blank - below is what I used.
=IF (OR($A2<>"",$B2<>""),
(IF(COUNTIFS($D$2:$D$12,$A2,$E$2:$E$12,IF($B2="","",$B2))=0,TRUE,FALSE)
)
)
This works by returning TRUE or FALSE from the following logical checks - if the final result is TRUE, then the formatting appears.
OR($A2<>"",$B2<>"") - Checks is either of the cells in the master are not blank. - If both cells are blank, this returns FALSE, and does not format anything (see A10:B10).
IF(COUNTIFS($D$2:$D$12,$A2,$E$2:$E$12,[see point 3])<1,TRUE,FALSE) - This counts the number of times that both the range $D$2:$D$12 contains the value of cell $A2, AND the range $E$2:$E$12 contains the value of cell $B2. If that number is <1, (zero matches), then the statement returns TRUE and implements the formatting.
IF($B2="","",$B2) - This nested IF statement checks if Cell $B2 is blank, and returns "" if it is blank, or keeps the value of $B2 otherwise. This is because COUNTIFS would see the cell as a 'zero' when blank otherwise (see A9:B9).
I have not used a similar nested if to check if $A2 is blank, because it should not be blank, so it's useful to highlight that the user has made an error in data entry here, too (see A2:B2 - this will remain red once the user inputs a name, as it will no longer match D2:E2.)
Reference image below:
I need to compare two columns I and L and copy matched result from M column. It is a list of 1000+ product codes (I,L) and EAN codes (M). So if cell I1 is found in range of L1:L1000 (lets say it found in L3 cell), then formula should copy the M3 cell.
Tried VLOOKUP and MATCH and some IF, but cannot figure it out how to make it work as it returns blank or REF! or N/A or errors-out completely. I'm desperate and don't know what i'm doing wrong...
=VLOOKUP(I1:I1164,L1:L1164,13,FALSE)
and with
=IF(ISNUMBER(SEARCH(I1,L1:L1000),M1," "")
Result should be in N column.
When using VLOOKUP, you need the lookup range to include both the range of values you're looking for (which MUST to be the first column) and the return values (whose column you specify as relative to the range. So in your case, you'll be looking up in L1:M1164 and using column 2 as return results (since column M is the second of L1:M1164).
Also, the value you're looking for will probably be just an item, relative to the current line. I'd thus try it that way (in N1):
=VLOOKUP(I1;$L$1:$M$1164;2;FALSE)
Wrapping it up in an IFERROR as suggested in SJR's answer might be a good idea too.
Try this
=iferror(index(m1:m1000,match(i1,l1:l1000,0)),"")
The match bit returns 3, the index bit then looks for the 3rd value in column M; the Iferror returns an empty string in the event of an error (i1 is not found).
I was not sure how to really create the question...
But the problem I am having is this: I have a list (in rows) that relate to a regulatory document, and after trying to create some sort of for loop or elaborate VLookUp/Index formula, I'm requesting help.
For example:
Now I want to use the rows to find the corresponding section in the document. I've already extracted and formatted the compliance document so it is in excel format.
So what I really need is this: a formula or VBA script that can
1. take the compliance number (for example 1A-1 which exist in Cell A3) and go find a cell (in single column D) that has JUST 1A-1, not 1A-1.1, not 1A-1.1.2, etc. and return it to the adjacent cell to 1A-1, for example.
Many thanks ahead of time... I am so lost!! :/
VLOOKUP vs INDEX/MATCH
You can do the 'lookup' two ways (that I'm aware of):
Using VLOOKUP:
The B3 cell contains your formula
=IF(ISERROR(VLOOKUP(A3,C:D,2,FALSE)),"",VLOOKUP(A3,C:D,2,FALSE))
where 'FALSE' is indicating there has to be an exact match and the data doesn't have to be sorted.
Using INDEX with MATCH:
The F3 cell contains the Index/Match formula
=IF(ISERROR(MATCH(A3,C:C,0)),"",INDEX(D:D,MATCH(A3,C:C,0)))
where '0' is indicating there has to be an exact match and the data doesn't have to be sorted.
INDEX/MATCH preferable!?
The MATCH function finds the position (row number if whole column is used) of the found match. This way (there's another) of using the INDEX function uses exactly this found match to return a cell's value in that position (row) in ANY specified column range (column). So they are the ideal combination.
With the VLOOKUP function you have to additionally specify the column index (range_lookup) of a range which could get complicated when the columns aren't adjacent as in this case. Most importantly, the function doesn't work if the lookup data is to the right of the match data.
VLOOKUP NOT WORKING! INDEX/MATCH STILL WORKING!
try this formula
The formula in cells
B2: =INDEX(E:E,MATCH(A2,F:F,0))
C2: =INDEX(G:G,MATCH(A2,F:F,0))
MATCH(A2,F:F,0) is finding Cell A2 in column F (0 means it will find
exact match) and will return the first row number when it would find that
INDEX(E:E,MATCH(A2,F:F,0)) will return contents of column E where row number is returned by the Match formula
is there a way to combine a search formula with a lookup or possibly use an if then statement. I think I have the first part working but need help with the second part. I am looking for values in column A and based on the values found in column A, I need to look at values in other columns and return the value found in that column.
Example, if column A contains value "car", I need to look at column B and return the value found in column B in column F , if column A contain value "boat", I need to look at column C and return the value found in column C in column F.
Any help would be much appreciated
Assuming that you have a list of possible values: car, boat, bike, plane, ... that would lead you to look for values in column B, C, D, E, ... I suggest you do the following:
Define the name "transportation" (whatever name you want to call it) with the types of transportation you need - for example, ={"car", "bike", "tram", "bus", "boat"} . On Office for Mac 2011 you do this with Insert->Name->Define... - for other versions of Excel it might be different (but note - you actually type both the = sign and the {} curly braces around the list of values you want to be able to look up). Put them in the order of the columns that you want.
For every lookup that you need, you can now write
=INDEX(B4:F4,0,MATCH(A4,transportation,0))
if the value (car, bus etc) is in cell A4, and you want to look up the corresponding value from columns B through F.
If you have column headings above your columns, you can use the MATCH function without having to define a name explicitly. For example, if you have car, bike, tram etc in cells B1:F1, you can use
=INDEX(B4:F4, 0, MATCH(A4, $B$1:$F$1, 0))
to do the lookup.
Explanation: the MATCH function (with third parameter 0) looks for the exact match for the first value (in cell A4 in this case) in the array that is the second parameter (either the named range, or the range with fixed address that I gave above). You then look up the appropriate cell using the INDEX function which gives you an offset into the range (B4:B4 in the above) of cells where you need to do the lookup.
I trust you can adapt this to your exact needs. Ask if you need more help.
The following formula is the simplest way I can think to do it:
In cell F1, the formula would be
=IF(A1="car",B1,C1)
This is case insensitive, so it should work for CAR as well. But bear in mind that this has the downside that with a formula this simple, ANY value in A1 other than "car" (not just "boat") would lead to the other value ending up in the F column.
=IF(A1="car",B1,IF(A1="boat",C1,""))