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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,561
Messages
6,125,538
Members
449,236
Latest member
Afua

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