How to insert external file link using open data file in a index match formula function of VBA

HH_Captain

New Member
Joined
May 25, 2021
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Dear Colleagues,

I want to Browse a file and give path to the VBA code over the Index match formula. Basically, the below formula for index match works within 2 sheets in the same workbook. I need to have option to source the data for index match with an option to open file and consider data from sheet(1) of that file which is opened.

Below is the code of VBA:

Sub MacroLynx()

Dim x As Integer, Y As Integer

Dim SourceRange As Range
Dim Lookrange As Range
Dim Header_Range As Range
Dim ws As Worksheet

Set wsd = Sheets("FARE (2)") 'I want to replace wsd with the Open data file code
Set WSVO = Sheets("FARE")
Set SourceRange = wsd.Range("A:G")
Set Lookrange = wsd.Range("A:A")
Set Header_Range = wsd.Range("1:1")

WSVO.Select

MyLastRow = WSVO.Cells(Rows.Count, 1).End(xlUp).Row
MyLastColumn = WSVO.Cells(6, Columns.Count).End(xlToLeft).Column


For x = 7 To MyLastRow
For Y = 2 To MyLastColumn

On Error Resume Next

WSVO.Cells(x, Y) = WorksheetFunction.Index(SourceRange, _
WorksheetFunction.Match(WSVO.Cells(x, 1), Lookrange, 0), _
WorksheetFunction.Match(WSVO.Cells(6, Y), Header_Range, 0))

Next Y
Next x

On Error GoTo 0

End Sub
 

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,224,824
Messages
6,181,186
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