Find Value from a Workbook and Return the Value next to the column

Razor_Rob

Board Regular
Joined
Aug 18, 2022
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hi

I would like a VBA code to look for the Employer Name (Column B) on a workbook name ExtOrgsList.xlsx then return the value on column A to a different workbook for example ImportName.csv both files are in the same folder.

the search should start from row 5 and all the way to the last record.

Sample Data of ExtOrgsList.xlsx

A B
310001 Employer Name 1
310002 Employer Name 2
310003 Employer Name 3
310004 Employer Name 4

then this info should copy and replace the value that are in column AN of the file ImportName.csv

Sample Data of ImportName.csv BEFORE the code
AN
Employer Name 1
Employer Name 2
Employer Name 3
Employer Name 4

Sample Data of ImportName.csv AFTER the code
AN
310001
310002
310003
310004


Thank you thank you so much in advance
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I found the below code but doesnt seem to do anything....

VBA Code:
Dim Cl As Range
    Dim Dic As Object
        
    Set Dic = CreateObject("scripting.dictionary")
    With wsDest
        For Each Cl In .Range("AN2", .Range("AN" & Rows.Count).End(xlUp))
            Dic(Cl.Value) = Cl.Offset(, 1).Value
        Next Cl
    End With
    With wsExtOrgsList
        For Each Cl In .Range("B5", .Range("B" & Rows.Count).End(xlUp))
            If Dic.exists(Cl.Value) Then Cl.Offset(, 1).Value = Dic(Cl.Value)
        Next Cl
    End With
 
Upvote 0
Duh, it was reversed, got it working

But

How do I make sure the search match the whole text in column B
ie i tested
Column A
330001
330002

Column B
Mac Constructions
Mac Construc


It returns the value as 330001, where the 2nd line should return 330002
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,403
Messages
6,119,309
Members
448,886
Latest member
GBCTeacher

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