Modify code to cycle through all the workbooks in the folder

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
I have written the following code that extracts several pieces of data from all the worksheets in that file. How can I modify the code (which I can move to a separate workbook, that would cycle through all the workbooks in a specific directory, creating one table of data for all the workbooks. The user needs to be able to select the folder location. Any help if really appreciated.

Code:
Option Private Module
Sub MakeTextOutput()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Dim wb As Workbook:  Set wb = ThisWorkbook
    Dim ws As Worksheet
        Set ws = wb.Sheets("TEXT")
             CopyST_TEXT
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.Goto Cells(ActiveWindow.SplitRow + 1, ActiveWindow.SplitColumn + 1)
End Sub
 
Sub CopyST_TEXT()
    For Each ws In Worksheets
        If ws.Name <>  "TEXT" And ws.Range("E13").Value > "0" Then
    'R13 - Straight Time
            Range("A500").End(xlUp).Offset(1, 0).Value = ws.Range("A1").Value       'Payroll
            Range("B500").End(xlUp).Offset(1, 0).Value = ws.Range("A2").Value       'Emp #
            Range("C500").End(xlUp).Offset(1, 0).Value = ws.Range("A3").Value       'Name 
            Range("D500").End(xlUp).Offset(1, 0).Value = ws.Range("A13").Value      'Div
            Range("E500").End(xlUp).Offset(1, 0).Value = ws.Range("B13").Value      'Dept
            Range("F500").End(xlUp).Offset(1, 0).Value = ws.Range("C13").Value      'CIP
            Range("G500").End(xlUp).Offset(1, 0).Value = ws.Range("D13").Value      'Shift      
            Range("H500").End(xlUp).Offset(1, 0).Value = ws.Range("E13").Value      'Hours  
            Range("I500").End(xlUp).Offset(1, 0).Value = "UE105"                    'Earnings Code
            Range("J500").End(xlUp).Offset(1, 0).Value = ws.Range("L13").Value      'Pay Rate
        End If
    Next ws
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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