Collate all spreadsheets .xls* in the current folder depending on a specific cell value.

excelente

New Member
Joined
Apr 28, 2011
Messages
4
Hi guys! I have a challenge for you. I am having a problem with multiple reports no uniformity of columns so I thought of these but I don't know how to do it. This is the scenario.

1. There are x numbers of spreadsheets and worksheets within with different column names in it.
2. I thought of putting a specific value in a hidden cell to let the collator know what to do and what range would it copy.
3. All spreadsheets that I want to collate have 4 column names that I want to copy. eg. ID, Name, Number, Status but columns arrangement are different from each other.
4. The collator then will check all the spreadsheets and the worksheets within them if cell AA has a value and copy columns depending on the value. For example: If the value of cell AA in the source spreadsheet is REPORT1 then it will copy columns B, C, D, F and paste it on the collators sheet columns A, B, C, D and if the value is REPORT2 the columns in which it will copy is A, D, G, H and copy it again in columns A, B, C, D of the collator sheet.
5. If possible, this will happen while the source spreadsheets in current folder is closed.
6. By the way, the source spreadsheets have different starting row.

I appreciate all the help big or small. Thank you.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi guys! I have a challenge for you. I am having a problem with multiple reports no uniformity of columns so I thought of these but I don't know how to do it. This is the scenario.

1. There are x numbers of spreadsheets and worksheets within with different column names in it.
2. I thought of putting a specific value in a hidden cell to let the collator know what to do and what range would it copy.
3. All spreadsheets that I want to collate have 4 column names that I want to copy. eg. ID, Name, Number, Status but columns arrangement are different from each other.
4. The collator then will check all the spreadsheets and the worksheets within them if cell AA has a value and copy columns depending on the value. For example: If the value of cell AA in the source spreadsheet is REPORT1 then it will copy columns B, C, D, F and paste it on the collators sheet columns A, B, C, D and if the value is REPORT2 the columns in which it will copy is A, D, G, H and copy it again in columns A, B, C, D of the collator sheet.
5. If possible, this will happen while the source spreadsheets in current folder is closed.
6. By the way, the source spreadsheets have different starting row.

I appreciate all the help big or small. Thank you.
Hi excelente
If the workbooks are isolated to a single directory so that they all have the same path, and they are the only workbooks in that directory, then they can be called without having to know their individual names. But the sheets are not that simple. If only the first sheet of each workbook is to be used, or if each sheet of each workbook is to be used, then those are easy enough to handle. But if the workbooks contain multiple sheets and only one or two randomly apply to the project, then that can get messy. All that is is needed to locate the correct columns is the column header string. Then as long as each worksheet has those column headers, spelled the same on each, then they can be found and applied as needed. So if you are looking for VBA code to help you, and can clear up how the workbooks and worksheets are organized, maybe someone will provide a method to do what you want.
 
Upvote 0
Hi JLGWhiz,

Thank you for the response, it seems like your the only person interested with my problem. I'm still trying to figure out how make things work. for now this is what I came up with. I hope all things will turn out well. :)

Code:
 Sub FireTheLazer()

    Dim fPath As String
    Dim sh As Worksheet
    Dim sName As String

    fPath = ThisWorkbook.Path + "\"

    With Application
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    sName = Dir(fPath & "*.xls*")


    Dim activeLastRow As String

    Do Until sName = ""

        If sName <> ThisWorkbook.Name Then
            With GetObject(fPath & sName)
                For Each sh In .Worksheets
                    With sh

                        activeLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1

                        If (.Range("BB1").Value = "REPORT1") Then
                            .Range("A2:A9").Copy
                            ThisWorkbook.Worksheets(1).Range("A" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                            .Range("B2:B9").Copy
                            ThisWorkbook.Worksheets(1).Range("B" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                            .Range("C2:C9").Copy
                            ThisWorkbook.Worksheets(1).Range("C" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                            .Range("D2:D9").Copy
                            ThisWorkbook.Worksheets(1).Range("D" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                            .Range("E2:E9").Copy
                            ThisWorkbook.Worksheets(1).Range("E" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                        ElseIf (.Range("BB1").Value = "REPORT2") Then
                            .Range("A2:A9").Copy
                            ThisWorkbook.Worksheets(1).Range("A" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                        ElseIf (.Range("BB1").Value = "REPORT3") Then
                            .Range("A2:A9").Copy
                            ThisWorkbook.Worksheets(1).Range("A" + activeLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                        End If

                    End With
                Next sh
                .Close True
            End With
        End If
        sName = Dir
        
    Loop
    
    

    With Application
        .Calculation = xlAutomatic
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0
You're probably getting a type mismatch because of this line
Code:
Dim activeLastRow As String
Change to
Code:
Dim activeLastRow As Long

When you initialize that variable, it is an integer value, so you need the Long integer data type.

You also might want to use
Code:
Dim wh As Workbook
Set wb = Workbooks.Open(fPath & sName)
Instead of
Code:
With GetObject(fPath & sName)
Then of course you would do away with the End If for that with statement, and use the wb variable to set up your sheet variables.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,636
Messages
6,125,961
Members
449,276
Latest member
surendra75

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