Avatar of ABINAYA MOHAN
ABINAYA MOHAN

asked on 

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!
VBA

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon