+ Reply to Thread
Results 1 to 3 of 3

Applying same formula to multiple workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    02-14-2020
    Location
    Hoboken
    MS-Off Ver
    2019
    Posts
    21

    Applying same formula to multiple workbooks

    I have a folder of about 20 Workbooks. I have a series of formulas that need to be applied onto all of these workbooks. Each workbook in the folder has values from A2:E722, with a header on the first row. The formulas refer to the values in this range. I have a formula for mean in column F, median in Column G. and average in Column H. Is there a way to apply this formula for all the workbooks across the board. Rather than copying and pasting the same formula to each workbook?

  2. #2
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Applying same formula to multiple workbooks

    Try something like this code...
    Sub Button1_Click()
    
        Dim wb1 As Workbook
        Dim wb2 As Workbook
        
        Dim fullfilename As String
        Dim filename As String
        
        Dim oFSO As Object
        Dim oFolder As Object
    
     
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        Set oFolder = oFSO.GetFolder(Range("B1").Value)
        Set wb1 = ActiveWorkbook
        
        
        For Each oFile In oFolder.Files
     
            Range("B2").Value = oFile.Name
            Application.ScreenUpdating = False
            
            fullfilename = Range("B1").Value & Range("B2").Value
            filename = Range("B2").Value
            
            Workbooks.Open fullfilename
            Set wb2 = ActiveWorkbook
            With Range("F2:F" & Cells(Rows.Count, "A").End(xlUp).Row)
                .Formula = "=AVERAGE($A$1:A1)"
            End With
            With Range("G2:G" & Cells(Rows.Count, "B").End(xlUp).Row)
                .Formula = "=MEDIAN($B$2:B2)"
            End With
            With Range("H2:H" & Cells(Rows.Count, "C").End(xlUp).Row)
                .Formula = "=AVERAGE($C$1:C1)"
            End With
        
        Workbooks(filename).Close SaveChanges:=True
        
        wb1.Activate
        Application.ScreenUpdating = True
        
        Next oFile
    
    End Sub
    as in attached workbook.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    02-14-2020
    Location
    Hoboken
    MS-Off Ver
    2019
    Posts
    21

    Re: Applying same formula to multiple workbooks

    thank you sir

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formula for applying multiple conditions
    By harshalcr9 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-14-2016, 08:29 AM
  2. Applying an IF formula in regards to multiple columns
    By Kirstyamanda in forum Excel Formulas & Functions
    Replies: 30
    Last Post: 04-12-2016, 11:35 AM
  3. Replies: 2
    Last Post: 03-29-2013, 06:19 PM
  4. Macro: Applying formula to multiple cells in excel (formula editing)
    By city in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 06:41 AM
  5. Applying formula from different workbooks
    By excel5111987 in forum Excel General
    Replies: 0
    Last Post: 09-09-2011, 07:20 AM
  6. Excel 2007 : Applying a formula to multiple worksheets
    By michael.ASTI in forum Excel General
    Replies: 2
    Last Post: 01-21-2011, 10:39 AM
  7. Applying the same formula to multiple cells
    By Peter1999 in forum Excel General
    Replies: 2
    Last Post: 05-03-2007, 05:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1