Macro to pull data from multiple workbooks

MattTonk

New Member
Joined
Mar 13, 2019
Messages
1
Hi everyone - I am trying to create a macro to pull a specific cell from multiple workbooks. This cell will remain the same throughout (A1). The issue I am running into is when the macro is ran it does not immediately identify the sheet. When ran it will force you to select the correct sheet instead of pulling directly from it (Sheet2 instead of Sheet1). All the files are located within the same folder. Any help is appreciated.


Sub GetDataClosedWB()
Dim MyPath As String, MyFile As String
ActiveSheet.UsedRange.Clear
MyPath = ThisWorkbook.Path & Application.PathSeparator
MyFile = Dir(MyPath, vbNormal)
Range("A1").Select
Do While MyFile <> ""
MyShName = Mid(MyFile, 1, Len(MyFile) - 4)
If MyFile <> ThisWorkbook.Name Then
ActiveCell.FormulaR1C1 = "='" & MyPath & "[" & MyFile & "]" & MyShName & "'!R1C1"
ActiveCell.Offset(0, 1).Value = MyFile
ActiveCell.Offset(1, 0).Select
End If
MyFile = Dir
Loop
Columns("A:B").AutoFit


End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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