-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMergedBookingReport.vb
112 lines (94 loc) · 4.26 KB
/
MergedBookingReport.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Sub UpdateMergedBookingReport()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This macro copies detailed data from a Booking Report and places the information into a '
' consolidated table saving only the latest record for each PID '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim FillRange As Range
Dim ShName As Worksheet
Dim DestSh As Worksheet
'Turn off Alerts and Screen updating
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Confirm user is ready to Run Report
Answer = MsgBox("Do you have the latest version of the Booking health report (from SharePoint) open?", vbQuestion + vbYesNo, "PID Health Open?")
If Answer = vbNo Then
'Code for No button Press
Exit Sub
Else
'Code for Yes button Press
''''''Select PID health Data ''''''''''''''''
Application.Goto Reference:=Worksheets("DATA").Range("A1")
Range("A2").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row - 3, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
''''''Copy PID Health data as values to new sheet ''''''''''''
Selection.Copy
Set ShName = ActiveWorkbook.Worksheets.Add
ShName.Name = "Data Extract"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("CD1").Select
Application.CutCopyMode = False
''''''Fill Cells with Report Week etc
ActiveCell.Formula = _
"=MID(CELL(""filename"",A1),FIND(""["",CELL(""filename"",A1))+1,10)"
Range("CD1").Select
'Selection.AutoFill Destination:=Range("BS1:BS264")
'AutoFill the range down
Last = Lastrow(ShName)
Selection.AutoFill Destination:=Range(Cells(1, "CD"), Cells(Last, "CD"))
''''''Copy data to move to merged file
Range("A1").Select
Range("A1").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
'Range("A1:BS264").Select
Selection.Copy
'Open the Combined PID Report XLSX
Workbooks.Open Filename:= _
"C:\Users\ctwellma\Documents\AS\Reports\Booking Report\CombinedReports\CombinedBookings.xlsx"
'Copy PID Health Detail
'Sheets("Merged Reports").Select
'Windows("MergedPIDReportFY12.xlsx").Activate
Set ShName = ActiveWorkbook.Worksheets("Merged Reports")
Last = Lastrow(ShName) + 1
Range(Cells(Last, "A"), Cells(Last, "A")).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Variables:
'Define Sheet we're using
Set DestSh = ActiveWorkbook.Worksheets("Merged Reports")
Last = Lastrow(DestSh)
'Select Full Active Range to be sorted
Range("A1").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select
'Sort Selection FIrst on PID (G) and then on report Quarter and Week (BS)
'Selection.Sort _
' Key1:=Worksheets("Merged Reports").Range("G1"), Order1:=xlAscending, Header:=xlGuess, _
' key2:=Worksheets("Merged Reports").Range("BS1"), Order1:=xlAscending, Header:=xlGuess
'Loop through to eliminate everything but latest info for each PID
'Last = Lastrow(DestSh)
'Firstrow = ActiveSheet.UsedRange.Cells(2).Row
' Lrow = Last + Firstrow - 1
' With DestSh
' For Lrow = Last To Firstrow Step -1
' If IsError(.Cells(Lrow, "G").Value) Then
'
'
' ElseIf .Cells(Lrow, "G").Value = .Cells(Lrow + 1, "G").Value Then
' If .Cells(Lrow, "BS").Value < .Cells(Lrow + 1, "BS").Value Then
' .Rows(Lrow).EntireRow.Delete
' End If
'
' End If
' Next
' End With
' End If
'Turn off Alerts and Screen updating
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub