Trying to Look Up and compare multiple columns to return TRUE

MikeXYZ7

New Member
Joined
Aug 11, 2017
Messages
35
Hello

I am struggling to work out the logic to determine a match between 2 dates, 2 products and one customer?

What I am trying to do is run a macro or formula to determine from the list where the SAME customer name (col A), matches with a RED & BLUE product with the same delivery date.

In the table below, I would want rows 4 & 5 to be highlighted as a match! And all other rows to be ignored.

Is anyone able to help me solve this conundrum?

Kind regards

Mike



ABC
1CUSTOMER NAMEPRODUCT COLOURDELIVERY DATE
2Cust 1REDFEB
3Cust 1REDFEB
4Cust 2REDMAR
5Cust 2BLUEMAR
6Cust 2REDMAR
7Cust 3BLUEAPR
8Cust 3REDMAY
9Cust 4BLUEAUG
10Cust 4BLUEAUG
11Cust 4BLUESEP

<tbody>
</tbody>
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG11Aug55
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant, P [COLOR="Navy"]As[/COLOR] Range, Col [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Txt = Dn.Value & Dn.Offset(, 2).Value
    [COLOR="Navy"]If[/COLOR] Not .Exists(Txt) [COLOR="Navy"]Then[/COLOR]
        .Add Txt, Dn.Offset(, 1)
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]Set[/COLOR] .Item(Txt) = Union(.Item(Txt), Dn.Offset(, 1))
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
   [COLOR="Navy"]Set[/COLOR] nRng = Nothing
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Col [COLOR="Navy"]In[/COLOR] Array("RED", "BLUE")
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] P [COLOR="Navy"]In[/COLOR] .Item(K)
            [COLOR="Navy"]If[/COLOR] P.Value = Col [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = P Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, P)
                [COLOR="Navy"]Exit[/COLOR] For
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] P
    [COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] nRng.Count = 2 [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Interior.Color = vbYellow
    [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] Col
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi Mick

Thank you for such a quick response. I've just tried the solution but have hit a roadblock in that I haven't come across the "With CreateObject("scripting.dictionary")" . I can see what this is doing and it seems ideal for what i am trying to do but i am unsure how to add Microsoft scripting Runtime?

I'll do some research and then try again - if you can let me know how to do this, that would be great - I'm running Win 10, Excel 2016.

Kind regards

Mike
 
Upvote 0
Hi Mick

It does work! You are a superstar! Thank you! I put the code into a module initially and hit a runtime error - but tried again by putting the code into the worksheet and it worked perfectly!

Thank you for the support!

All the best

Mike
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top