Copying Rows from diffferent workbooks to collated worksheet by filename

Amy2011

New Member
Joined
Sep 15, 2011
Messages
14
So i've searched the forum endlessly to an answer to this and can't find one.

I have a master folder with 52 .xlsm files

I want to copy Range B29:BA29 from each workbook (these numbers are calculated averages so I want the value, not the formula)

Then, I have a master workbook with all of the 52 .xlsm filenames in column A - and I want to paste range B29:BA29 into the row which corresponds to its filename, starting at column I

so i guess cells (Ifilename:BHfilename)
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
This is what i currently have... when i run the macro it doesn't come up with an error.... but the data does not appear in the collated sheet either...

(keep in mind im new to this, so this code might not be the best way it can be done)


Code:
Option Explicit
Sub ProcessAllFilesInSubjectFolders()
Dim MyPath As String, fName As String
Dim wbOpen As Workbook
Dim MySubjects As Range, Subj As Range
Dim Book_Name_Output As Workbook
Set Book_Name_Output = ActiveWorkbook

MyPath = "G:\AH Cricket"
Set MySubjects = ThisWorkbook.Sheets("Sheet1") _
               .Range("A:A").SpecialCells(xlConstants)
For Each Subj In MySubjects
    fName = Dir(MyPath & Subj & "\*.xlsm")   'get first filename for this folder
    
    Do While Len(fName) > 0                 'process each file one at a time
        
        Set wbOpen = Workbooks.Open(MyPath & Subj & fName)
        With wbOpen
            Range("B29:BA29").Select
            Selection.Copy

            .Close False    'closes and saves, change to FALSE to not save changes
        End With
'data output
            Book_Name_Output.Activate
            Sheets("Collated Data").Select
            Cells(fName, 9).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False                       
        fName = Dir
                 'get next filename
    Loop
    
Next Subj

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

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