VBA :Match columns from from workbook A & B, return another column from workbook A to workbook B

I have 2 workbooks A & B.The workbooks are already defined.

I have an issue with part of my code where I am trying to compare column A from workbook A and Column D from Workbook B. If it matches then I want to copy corresponding column B to Workbook column E.

I started to write the following code but not sure how to proceed further in comparing the columns and copying as I am fairly new to VBA. I am not trying to match row by row, I am checking the entire column.


Dim strRangeToCheckA As Range
Dim strRangeToCheckB As Range
Dim strRangeToCheckC As Variant

Set strRangeToCheckA = RSC.Sheets("Balance").Range("A:G")
Set strRangeToCheckB = Brostacc.Sheets("Stock").Range("A:U")
Set strRangeToCheckC = Brostacc.Sheets("Stock").Range("U:U")

If Application.VLookup(LookFor, strRangeToCheckA, 2, False) = Application.VLookup(LookFor, strRangeToCheckB, 1, False) Then
  strRangeToCheckC = Application.VLookup(LookFor, strRangeToCheckA, 7, False)
End If

I appreciate the help and Thanks in Advance!
ABINAYA MOHANAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
So you want to go through column A on the sheet 'Balance' in one workbook and find matched in column D on the sheet 'Stock' in the other workbook?

If a match is found you wan to return the value from column B on sheet 'Stock' and put it in column E on sheet 'Balance'?

Is that correct?
0
ABINAYA MOHANAuthor Commented:
Yes,that is my Scenario.
0
Martin LissOlder than dirtCommented:
Can you supply sample workbooks?
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

ABINAYA MOHANAuthor Commented:
Attached is the Sample Balance sheet in which I have added comments in it as in which column has to be compared and which column has to be copied and also Sample Stock sheet.
Sample-Balance-Sheet.xlsx
Sample-Stock-Sheet.xlsx
0
Martin LissOlder than dirtCommented:
You say
trying to compare column A from workbook A and Column D from Workbook B.
Column "A" on your supplied Sample-Balance-Sheet is labeled "DealerNum" an Column "D" on your supplied Sample-Stock-Sheet is labeled "Tel nbr" which seems incorrect. I assume you meant
trying to compare column A from workbook A and Column B from Workbook B.
0
Martin LissOlder than dirtCommented:
And once a match is found, is it the telephone number you want to copy?
0
ABINAYA MOHANAuthor Commented:
Yes Sorry for confusion,The comments in the Workbook is the correct one.
0
Martin LissOlder than dirtCommented:
I guess I should have read them <embarrassed>
0
Martin LissOlder than dirtCommented:
Which workbook should contain the code?
0
ABINAYA MOHANAuthor Commented:
Its a different workbook entirely different from these 2 files.I have defined the main code file as "SourceFile"
0
Martin LissOlder than dirtCommented:
Try this. There are a couple of places where you'll need to change the paths to your workbooks.
29069303.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ABINAYA MOHANAuthor Commented:
Thank you !
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
0
ABINAYA MOHANAuthor Commented:
I am trying to do the same kind of find and copy with another new file. But when I do that the performance of the vba goes down.It takes almost 25 minutes to run the entire program. Is there any particular reason that can happen? When I try to do any kind of operation with the new file the performance goes down.
0
Martin LissOlder than dirtCommented:
I am trying to do the same kind of find and copy with another new file. But when I do that the performance of the vba goes down.It takes almost 25 minutes to run the entire program. Is there any particular reason that can happen? When I try to do any kind of operation with the new file the performance goes down.
You should open a new question for that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.