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.
[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: