VBA place hours worked on master sheet depending of the date worked in that week

guhaseelan

New Member
Joined
Feb 3, 2014
Messages
17
[Supplier Timesheet Workbook][1]
[Master Sheet][2]
[1]: https://i.stack.imgur.com/zG324.jpg
[2]: https://i.stack.imgur.com/REaty.jpg

Hi! I need some help with this excel VBA. The pics above show the source sheets "Supplier Timesheet Workbook" that will be consolidated into the "Master Sheet". The VBA that I have resides in the "Master Sheet" and when pressed consolidates relevant info from multiple "Supplier Timesheet Workbooks".

I need some one more thing that the VBA below needs to do when pressed. In the "Supplier Timesheet Workbook" in cell B12 there is the date. With the hours worked corresponding in cell i12. Depending on the date compared to the week ending date in cell i6. The hours need to go in a particular column in the "Master Sheet". Looking at the "Master Sheet" pic this will make more sense. e.g. if there is 4 hours worked on the 15th it will go in column K. If 5 hours worked on the 17th it will go in column M.

Hope this makes sense. Note that cell i6 have automatically got the week ending date based on the dates entered in column B dates.

Code:
Public Sub Consolidate_to_master()
    Dim wksMaster As Worksheet
    Dim wks As Worksheet
    Dim rng As Range
    Dim i As Integer
    Dim wkb As Workbook
    Dim Filename As String
    Dim Path As String
    Dim Wb1 As Workbook, wb2 As Workbook
    Path = "[URL="file://\\ttsnas02\user_mdocs$\tdf8273\Documents\Rob\External"]\\ttsnas02\user_mdocs$\tdf8273\Documents\Rob\External[/URL] supplier timesheet\CSV Supplier Main\Inbox folder"  'CHANGE PATH
    Filename = Dir(Path & "*.xl??")
    ' bind the master worksheet to access it later on
    ' change index if needed
    Set wksMaster = ActiveWorkbook.Worksheets(1) ' or ThisWorkbook
    i = 3
    
    Do While Len(Filename) > 0  'IF NEXT FILE EXISTS THEN
        Set wkb = Workbooks.Open(Path & Filename)
        ' loop through range in worksheet with index 1 (the first)
        ' change index if needed
        With wkb.Worksheets(1)
            For Each rng In .Range("L12:L23")
                ' if there is a value in the cell
                If rng <> vbNullString Then
                Range(Selection, Cells(Rows.Count, Selection.Column).End(xlUp)).Select
                    wksMaster.Range("A" & i) = .Range("J8")
                    wksMaster.Range("C" & i) = .Range("J9")
                    wksMaster.Range("E" & i) = rng
                    ' increment i
                    i = i + 1
                End If
            Next
        End With
        wkb.Close True
        Filename = Dir
    Loop
End Sub
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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