Match Criteria in One Workbook with Criteria in Another Workbook

ozbeachbum

Board Regular
Joined
Jun 3, 2015
Messages
161
Office Version
  1. 2021
Platform
  1. Windows
Hi,
I am trying to retrive data from one workbook, if the criteria in that workbook matches the criteria in the workbook where I want the data to be returned.

I trust the following explanation makes sense.

Workbook to retrieve data from:
Workbook Name 19 Worksheet Name App - Web Site Data Range for Match F70:F333 Data Range for Retrieval AK70:AK333
Workbook for match & result:
Workbook Name 01 Worksheet Name (ph) drp Range for Match D70:D110

IF 01 (ph) drp D70:D110 matches 19 App - Web Site F70:F333 return AK70:AK333


Any assistance gratefully accepted.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Where in (ph) drp do you want to return the data?
 
Upvote 0
Make sure that both workbooks are open. Place this macro in the "01" workbook and run it from there.
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, v1 As Variant, v2 As Variant, dic As Object
    Set desWS = ThisWorkbook.Sheets("(ph) drp")
    Set srcWS = Workbooks("19.xlsx").Sheets("App - Web Site")
    v1 = srcWS.Range("F70:F333").Resize(, 32).Value
    v2 = desWS.Range("D70:D110").Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v1) To UBound(v1)
        If Not dic.exists(v1(i, 1)) Then
            dic.Add v1(i, 1), v1(i, 32)
        End If
    Next i
    For i = LBound(v2) To UBound(v2)
        If dic.exists(v2(i, 1)) Then
            desWS.Range("AK" & i + 69) = dic(v2(i, 1))
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,562
Messages
6,131,422
Members
449,651
Latest member
Jacobs22

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