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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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