Find value based on multiple criteria

edgarsrom

New Member
Joined
May 7, 2014
Messages
34
Office Version
  1. 2013
Hello,

I have got stuck completely with the following situation:

In sheet 1 I have information about 1) AN code(full part code), 2)part code 3) year part fits(from-to)

In sheet 2 I have only information for 2) part code and 3) year part fits(exact year)

question is: How do I find AN code in sheet 2 based on information I have(part code and exact year) from sheet 1? Also same AN code can fit for two same part codes therefore I would need to look by year(I think) :(

Example:

Sheet 1 data:
COL A: B: C: D: E: F: G: H:
AN CODE:Part code Table with years(from - to):
AN110011100120002001200220032004
AN110011100120042005
AN1100211002199920002001200220032004
AN11002110022001200220032004
AN10031100320012002
AN1003110032002

<tbody>
</tbody>

Sheet 2 data:
COL A: B: C:
Year:Part code: AN code:
200411001
200511001
200211002
200211003

<tbody>
</tbody>


Any ideas please?

Thanks in advance!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this for results in sheet2 column "C".
Code:
[COLOR="Navy"]Sub[/COLOR] MG25Sep19
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
    Ray = Sheets("Sheet1").Cells(1).CurrentRegion
    [COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
        .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
    [COLOR="Navy"]For[/COLOR] Ac = 3 To UBound(Ray, 2)
        [COLOR="Navy"]If[/COLOR] Not IsEmpty(Ray(n, Ac)) And Not .exists(Ray(n, Ac) & Ray(n, 2)) [COLOR="Navy"]Then[/COLOR]
            .Add Ray(n, Ac) & Ray(n, 2), Ray(n, 1)
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] .exists(Dn.Value & Dn.Offset(, 1).Value) [COLOR="Navy"]Then[/COLOR]
        Dn.Offset(, 2) = .Item(Dn.Value & Dn.Offset(, 1).Value)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you so much for this code!!! It works perfect!!! One last question when you get a minute, could you please describe in couple words how this code is working?

Really appreciate solution provided!
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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