Академический Документы
Профессиональный Документы
Культура Документы
'
' JobMerger Macro
' Merges Jobs from 'merge' folder.
'
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'Change folder path to where the Excel files are located.
Set dirObj = mergeObj.Getfolder("Z:\Downloads from Chrome\merge")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
'A2 refers to the start point of where the files will be merged.
'Z refers to the end column.
'A50000 refers to the starting column and maximum number of rows to be
merged.
Range("A2:Z" & Range("A50000").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Do not change the following column. It's not the same column as above
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
Cells(1,
1) = "Commit End"
2) = "Service Order No."
3) = "Exchange Code"
4) = "Time Slot"
5) = "Estimated Activity Time"
6) = "Activity Type"
7) = "Customer Name"
8) = "Address"
9) = "Suspend Comment"
10) = "Not Done Comments"
11) = "Activity Status"
12) = "Primary Work Skill"
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:L1000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Names for cells.
Cells(2,
Cells(3,
Cells(4,
Cells(5,
Cells(6,
14)
14)
14)
14)
14)
=
=
=
=
=
"Jobs Complete"
"Jobs Incomplete"
"Jobs Suspended"
"Jobs Started"
"Total Jobs"
14)
14)
14)
14)
=
=
=
=
"TMP Booked"
"TMP Required"
"TMP Issues Unaccounted For"
"Total TMP Related Issues"
=
=
=
=
=
"=COUNTIFS(C[-4],""completed"",C[-13],""<>"")"
"=COUNTIFS(C[-4],""not done"",C[-13],""<>"")"
"=COUNTIFS(C[-4],""suspended"",C[-13],""<>"")"
"=COUNTIFS(C[-4],""started"",C[-13],""<>"")"
"=COUNTIF(C[-13],""<>"") - 1"
Cells(2,
Cells(3,
Cells(4,
Cells(5,
=
=
=
=
"=(RC[-1]/R[4]C[-1])"
"=(RC[-1]/R[3]C[-1])"
"=(RC[-1]/R[2]C[-1])"
"=(RC[-1]/R[1]C[-1])"
16).FormulaR1C1
16).FormulaR1C1
16).FormulaR1C1
16).FormulaR1C1
Cells(8, 15).FormulaR1C1 = _
"=COUNTIFS(C[-5],""*customer*"",C[-5],""*reschedule*"") + COUNTIFS(C[5],""*customer*"",C[-5],""*rebook*"")"
Cells(9, 15).FormulaR1C1 = _
"=COUNTIFS(C[-5],""*customer*"",C[-5],""*not available*"") + COUNTIFS(C[5],""*customer*"",C[-5],""*cannot get hold*"") + COUNTIFS(C[5],""*customer*"",C[-5],""*can't get hold*"") + COUNTIFS(C[5],""*customer*"",C[-5],""*not home*"") + COUNTIFS(C[-5],""*customer*"",C[5],""*not at home*"") + COUNTIFS(C[-5],""*customer*"",C[-5],""*not
answering*"") + COUNTIFS(C[-5],""" & _
"*customer*"",C[-5],""*unavailable*"") + COUNTIFS(C[-5],""*customer*"",C[5],""*waiting*"") + COUNTIFS(C[-5],""*customer*"",C[-5],""*need access*"") +
COUNTIFS(C[-5],""*customer*"",C[-5],""*cant provide*"") + COUNTIFS(C[5],""*customer*"",C[-5],""*not answering*"")" & _
""
Cells(10, 15).FormulaR1C1 = _
"=COUNTIFS(C[-5],""*customer*"", C[-5],""*consent*"") + COUNTIFS(C[5],""*customer*"", C[-5],""*requires*"") + COUNTIFS(C[-5],""*customer*"", C[5],""*neighbour*"") + COUNTIFS(C[-5],""*customer*"",C[-5],""*doesn't have*"")"
Cells(11, 15).FormulaR1C1 = "=R[1]C - SUM(R[-3]C:R[-1]C)"
Cells(12, 15).FormulaR1C1 = "=COUNTIF(C[-5],""*customer*"")"
Cells(14, 15).FormulaR1C1 = _
"=COUNTIFS(C[-5],""*tmp*"",C[-5],""*confirmed*"") + COUNTIFS(C[5],""*tmp*"",C[-5],""*require*"")"
Cells(15, 15).FormulaR1C1 = _
"=COUNTIFS(C[-5],""*tmp*"",C[-5],""*required*"") + COUNTIFS(C[5],""*tmp*"",C[-5],""*need*"") + COUNTIFS(C[-5],""*tmp*"",C[-5],""*not
booked*"") + COUNTIFS(C[-5],""*tmp*"",C[-5],""*scheculed*"")"
Cells(16, 15).FormulaR1C1 = "= R[1]C - SUM(R[-2]C:R[-1]C)"
Cells(17, 15).FormulaR1C1 = "=COUNTIF(C[-5],""*tmp*"")"
'ROW related job counts.
Cells(19, 15).FormulaR1C1 = "=COUNTIF(C[-5],""*row*"")"
'Health and Safety related job counts.
Cells(21, 15).FormulaR1C1 = _
"=COUNTIF(C[-5],""*h&s*"") + COUNTIF(C[-5],""*health and safety*"")"
'Cost related job counts.
Cells(23, 15).FormulaR1C1 = "=COUNTIF(C[-5],""*high cost*"")"
'Jobs (un)accounted for.
Cells(25, 15).FormulaR1C1 = "=SUM(R[-13]C,R[-8]C,R[-6]C,R[-4]C,R[-2]C)"
Cells(26, 15).FormulaR1C1 = "=SUM(R[-23]C-R[-1]C)"
Cells(25, 16).FormulaR1C1 = "=(RC[-1]/R[-22]C[-1])"
Cells(26, 16).FormulaR1C1 = "=(RC[-1]/R[-23]C[-1])"
'Sets the P column to Percentage
Range("P:P").NumberFormat = "0%"
'AutoFits the worksheet columns.
Columns("A:P").AutoFit
End Sub