Highlight duplicates not next to each other using conditional formatting (Larger Dataset) - vba

We have a list of product numbers in Excel in a certain order. For reasons I won't get into, we need to highlight when there are duplicates that aren't next to each other.Currently, I'm using this formula in a conditional format to do the job.
=AND(COUNTIF($A$2:$A$82,$A2)>1,$A1<>$A2,$A2<>$A3)
This mostly works well except in cases where there are pairs of duplicates like in the example below, we would want FO-1694 to be highlighted, because they aren't all next to each other. But we would not want NIS0257 to be highlighted because they are.
Currently
Ideally, this is what we want to see...
Expected
I originally asked this same question January 30th (link) and I received what seemed to be a working solution with the conditional formatting formula
=NOT(AND(A2=OFFSET(A2,COUNTIF($A2:$A$82,A2)-1,0),A2=OFFSET(A2,-(COUNTIF($A$2:$A2,A2)-1),0)))
While this original answer appears to work for a small group of data (example), it does not function as needed on much larger datasets like the ones I'll be dealing with (images below are of the issues with the larger dataset). I've adjusted the formula as necessary to accommodate the larger range, so the conditional formatting formula you see in the larger dataset pictures & file is
=NOT(AND(A2=OFFSET(A2,COUNTIF($A2:$A$5422,A2)-1,0),A2=OFFSET(A2,-(COUNTIF($A$2:$A2,A2)-1),0)))
Cells with the arrow pointing at them should be highlighted
For the last picture, even though it's the end of the range the cells should still be highlighted since they're blank and I need all blank cells in the range to be highlighted too.
The full file with the larger dataset can be downloaded from my dropbox account using this link.

I should have thought of those problems:
=NOT(AND(IFERROR(COUNTIF(OFFSET(A1,0,0,-COUNTIF($A$1:$A1,A2)),A2),0)=IFERROR(COUNTIF($A$1:$A1,A2),0),IFERROR(COUNTIF(OFFSET(A3,0,0,COUNTIF($A3:$A$5422,A2)),A2),0)=IFERROR(COUNTIF($A3:$A$5422,A2),0),A2<>""))
Should do it.

I'm not sure if this would work for you
=IF(COUNTIF($A$1:$A$8,A2)>2,1,IF(AND(COUNTIF($A$1:$A$8,A2)=2,A1<>A2,A3<>A2),1,0))
I've tested it on a test bit of data, and seems to work. You need to check for the 1st row, as you cant check the previous cell, so the A1<>A2 part..
1 being true condition on my test so would need tweaking for conditional formatting.
Enjoy.

Related

Select column and filter contents before searching on another worksheet

I´m trying to wirte a code and need some help.
I´ve managed to write parts of it using many sources around the web, but got to a point where I can´t find something to use as model or maybe find the right function.
I have an excel workbook with 2 worksheets, on the first one I have data from income and payments. With the code below I´ve managed to sort out the payments by eliminating blank cells from a range on "Plan1" and then copied to the other worsheet - "Plan2"
On Plan2 I get the following results:
Now, as you may see most of the codes are ending in "01".
What I need is:
After selecting column C; - done
Get all the values and search for them on Plan1, but removing the trailing "01" from them (since they vary in length) before search and then color the results on Plan1.
Advices please.
EDIT: I need to ignore the lines that do not end on "01". The full column will be selected.

Highlight Duplicates Not Next To Each Other Using Conditional Formatting

We have a list of parts in Excel in a certain order. For reasons I won't get into, we need to highlight when there are duplicates that aren't next to each other. Currently, I'm using this formula in a conditional format to do the job.
=AND(COUNTIF($A$2:$A$82,$A2)>1,$A1<>$A2,$A2<>$A3)
This mostly works well except in cases where there are pairs of duplicates like in the example below, we would want FO-1694 to be highlighted, because they aren't all next to each other. But we would not want NIS0257 to be highlighted because they are.
Currently
Ideally, this is what we want to see...
Expected
Any ideas on this could be achieved using conditional formatting?
Note: I have directly posted this from a past post on the SuperUser Forum (Link) as I am in need of this EXACT conditional formatting for the EXACT same circumstances. I do not take credit for the construction of this post, but only hope to obtain an answer for a question that previously went unanswered.
Use this formula:
=NOT(AND(A2=OFFSET(A2,COUNTIF($A2:$A$82,A2)-1,0),A2=OFFSET(A2,-(COUNTIF($A$2:$A2,A2)-1),0)))
If changing the range then make sure to pay attention to what is marked as absolute and relative.

Function that searches for the exact same date or the closest one in the past + one extra condition

This is a continuation of " Is it possible to write a VBA code that searches for the exact same data or the closest one in the past? "
Basically I would like to expand the function that #Jeeped posted but for some reason it's not going as planned eventhough I'm doing the same stuff he showed.
The extra condition in this case is that the machine used to produce the juice must be equivalent to the machine of the parameters.
(the image of what I'm doing)
Basically if a juice is made on 29/09 with machine M0 for example then I want to have the parameters that were used for that juice. Obviously the parameters of 30/09 weren't used but the parameters of 25/09 for machine M0 were used.
I edited the code #Jeeped posted in my previous question to the following
=IFERROR(INDEX(C$2:C$10, MIN(INDEX(ROW($1:$10)+($A$2:$A$10>$F2)*1E+99+($B$2=$G$2),,))),"")
But I get an error and I'm not sure why but I have a feeling it has to do with what I wrote ($B$2=$G$2) but how do I fix it?
DISCLAIMER: the percentages used are fictive, it's just a function I need to get working for several Workbooks that will automate some work I need to do every month.
It looks like you want to add the condition that columns B should match G2. This should do the trick.
=IFERROR(INDEX(C$2:C$10, MIN(INDEX(ROW($1:$9)+(($A$2:$A$10>$F2)+($B$2:$B$10<>$G2))*1E+99,,))),"")
This type of formula does not make direct matches. It excludes everything that doesn't match and then accepts whatever is left over. So like the date in F2 is compared to the dates in column A and anything that is larger (i.e. later) is multiplied by a very large number. We do the same to the machine ID in G2. Anything that does not match the machines in column B get multiplied by the same very large number. By mathematically excluding anything that doesn't fit, we are left with what does fit.
It is also important to note that the ROW(1:9) is the position within C2:C10 or A2:A10, not the actual row on the worksheet.
Addendum: With the dates now unsorted, I can provide both a standard and an array formula to compensate. The array formula for I2 is,
=SUMIFS(C$2:C$10,$A$2:$A$10,MAX(IF($A$2:$A$10<=$F2,IF($B$2:$B$10=$G2,$A$2:$A$10))),$B$2:$B$10,$G2)
This must be finalized with Ctrl+Shift+Enter rather than simply Enter. Once entered correctly, it can be filled both right and down. Next is a standard formula that does not require Ctrl+Shift+Enter but accomplishes the same thing. Your results should resemble the following image.
=SUMIFS(C$2:C$10, $A$2:$A$10,MAX(INDEX(($A$2:$A$10<=$F2)*($B$2:$B$10=$G2)*($A$2:$A$10),,)),$B$2:$B$10,$G2)
    
I think the formula below might answer your question. Please see the image for reference.
Formula Used: =INDEX($D$2:$E$7,MATCH(1,($B$2:$B$7<$H3)*($C$2:$C$7=$I3),0),1)
Please note - this requires your date of parameter change to be sorted from newest to oldest.
To apply this formula, press CTRL+SHIFT+ENTER after writing the formula. This is required for excel to understand that this should function as an Array formula. On doing so, excel will automatically add the curley brackets at the beginning and end of the formula as can be seen in the image.
Only small difference for formula to get %Oranges will be replacing the last 1 by 2.
INDEX($D$2:$E$7,MATCH(1,($B$2:$B$7<$H3)*($C$2:$C$7=$I3),0),2)
Hope this answers your question. Please let me know if you need further assistance.

Excel Vlookup Missing data unless re-typed or select and enter?

Google has not found the solution i need so i thought i would try the genius on here to the never ending Excel issue I'm having.
Running a banking reconciliation workbook and slowly adding bits of VBA together to automate some of the tasks, one I'm working on now is finding large quantities of money and renaming their Identifier from a bank statement to same ID in our cashbook to they are found and will balance out.
To do this I'm running a IF(Vlookup()) returning a yes or no on the cash value and then reordering them once they are found so i can line them up and match them correctly.
The main issue I've got here is the vlookup is ignoring some values which i can see and saying no not found and i messed around figuring out why and until i clicked to edit the cell and then pressed enter not changing the amount and all of a sudden found and it only finds it in the vlookup if i click the cell and press enter.
I have tried Formatting, changing calculation to automate and tweaked the vlookup to include a +0 as well as changing the exact match to approximate and it still won't find it, i even tried trimming and checked the Len for whitespace and both equal the same.
Currently trying a for loop to select a cell and change it to itself so it mimics the select and enter but it runs slow and crashes.
Anyone got a decent idea of fixing this miss when searching
This often happens to me when pasting data from somewhere. It may have been pasted as text but then when you edit and press enter it changes to numeric.
The solution is to use =VALUE() to change the numbers to numeric.
Or when you paste the data from another source choose paste special as text.
VLOOKUP works strangely when is asked to do an approximate match with the look-up table unsorted by the look-up column.
If you're sure that an exact match should be enforced in your look-up column, try something along the lines of:
VLOOKUP(<lookup_value>, <table_array>, <col_index_num>, FALSE)
where <lookup_value>, <table_array>, <col_index_num> should be replaced with the values that you use in your look-up.

Excel - How do I find all relevant rows by typing unique invoice# listed Col A

I have a Worksheet with 10 columns and data range from A1:J55. Col A has the invoice # and rest of the columns have other demographic data. Goal is to type the invoice number on a cell and display all the rows matching the invoice number from col A.
Besides auto filter function, the only thing comes to my mind is VBA. Please advice what is the best way to get the data. Thanks for your help in advance.
Alright, I'm pretty proud of this one. Again avoiding VBA, this one uses the volatile formula OFFSET to keep moving its VLOOKUP search down the table until it's found all matches. Just make sure you paste enough rows of the formula that if there are many matches, there's room for all of them to appear. If you put a border around your match area then it would be clear if you ever ran out of room and needed to copy down the formula some more.
Again, in the main section, it's just a single formula (using index):
=IFERROR(INDEX($A$1:$J$200,$M3,MATCH(N$2,$A$1:$J$1,0)),"")
This gets to be so simple because the hard work of the lookup is done by an initial column which looks up the next row that matches the invoice number. It has the formula:
=IFERROR(MATCH($L$2,OFFSET($A$1:$A$200,M2,0),0)+M2," ")
Here is the working example that goes with those formulas:
Let me know if you need any further description of how it works, but it mostly uses the same rules as above so that it's robust in copying and moving around.
I've uploaded the Excel file so you can play with it, but everything you need to reproduce this feature should be in this solution.
Google Docs - Click link and hit Ctrl+S to download and open in Excel.
A popular solution to this problem is a simple VLookup. Lookup the invoice the user types in on the table A1:J55, and then return an adjascent column's data.
Here's an example of it working:
The formula in the highlighted cell is:
=VLOOKUP($L3,$A:$J,MATCH(N$2,$1:$1,0),FALSE)
What's nice about this formula is you only need to type it once and then you can copy it across and it'll automatically pick out the correct column of the table (that's the match part). The rest is very simple:
The first part says lookup value $L3 (the invoice number typed in),
The second part says look it up in range $A:$J (which is where your table is located). I've shown how you can select the entire columns $A:$J so that you can add and remove data without worrying about adjustin the range in your lookups. (Excel takes care of optimizing the formula so that unused cells aren't checked)
The third part picks the column from which the resulting data will be drawn once a matching row is found.
The FALSE part is an indication that the invoice number must match exactly (no approximate matching allowed)
The $ signs ensure that fixed ranges like the location of your source table ($A:$J) and your lookup value ($L3) don't get automatically changed as you copy the formula across for multiple columns.
The formula is pretty easy to adapt if you want to move around your table and the area where you do your lookup. Here's an example:
Bonus
If you want to add a little spiff, you can add a dropdown to the Invoice # field so that the user gets auto-completion and the option to browse existing values like so: