Copy formula to multiple workbooks

egobrain

New Member
Joined
Aug 24, 2020
Messages
4
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there,

I need your help guys. I have hundred of excel workbooks and want to add extra data to each one. For example, I need to write lookup formula in one cell to retrieve data from one source file and then copy this formula to the same cell in every excel file placed in same folder. I know VBA will be necessary for this task but didn't find any solutions with google. Could you help me out to avoid this routine?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In which sheet and range is the data you want to retrieve in the source file? Into which cell and sheet do you want to copy/paste the source data? What is the full path to the folder containing your destination files? What is the extension of those files (xlsx, xlsm)? Are they the only files in that folder?
 
Upvote 0
Well here is the situation: I have hundreds of excel files containing data about each project. In workbook has only one sheet. Unique project number is placed, let's say, in B2 cell in every workbook. There is another workbook where these unique numbers are listed in one column and the names of the project managers in another column. All these workbooks are place in the same folder and each one has unique name. I want to write simple lookup formula to get project manager's name in C3 cell for each workbook. Extension of these files are xlsx.
 
Upvote 0
Let's assume that the unique numbers are in column A and the names of the project managers are in column B. Do you want to find the unique number in B2 in every workbook in column A and return the corresponding project manager's name in C3 of every workbook? What is the full path to the folder?
 
Upvote 0
Exactly. I want to add each project file the project manager's name. If it was 10 or 20 workbooks then it would be possible to open each workbook and write simple vlookup, but there are too many projects so its practically impossible to do it manually, at least I can't do that.
Honestly, I don't understand why does the full path of folder matter?
 
Upvote 0
ok, understand. But I don't think it's a big deal. If there were a marco I would change the path
 
Upvote 0
Try this macro. Change the folder path (in red) to suit your needs.
Rich (BB code):
Sub GetName()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWB As Workbook, fnd As Range
    Set srcWS = ThisWorkbook.Sheets(1)
    Const strPath As String = "C:\Test\" 'change folder path to suit your needs
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set desWB = Workbooks.Open(strPath & strExtension)
        Set fnd = srcWS.Range("A:A").Find(Sheets(1).Range("B2").Value, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            Sheets(1).Range("C3") = fnd.Offset(, 1)
        End If
        desWB.Close True
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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