VBA Coding to Compare different workbooks

vignesh_thegame

New Member
Joined
Sep 30, 2013
Messages
48
Hi,

I have plenty of excels and each of them are paired. ( 2 workbooks for a project).

I need to compare both workbooks using vlook up formula.

I did this by recording macro, and it works for that pair of spreadsheet alone.

The issue is, it is recording the spreadsheet name, so if i use that macro for another pair of spreadsheet, its not working as that workbooks file name are different.

I need a help to run the vlookup with any two opened workbooks and should not worry about file name:

Compare Macro
'

'
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],[Data2.xlsx]Sheet1!C1:C3,3,0)"
Range("F2").Select
Selection.Copy
Range("F2").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("Sheet2").Select
Range("F2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],[Data2.xlsx]Sheet1!C1:C3,3,0)"
Range("F2").Select
Selection.Copy
Range("E2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Selection.End(xlUp).Select
End Sub

I posted same files to below link:
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,141,773
Messages
5,708,453
Members
421,570
Latest member
BaileyJ

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
Top