Sub bupdate_srvcpda(ByRef trigger_cancel As Boolean)
'Stop
Dim lastrow As Long
Application.ScreenUpdating = False
With ws_master
.Activate
mbevents = False
.Unprotect
srvcs_no = Application.WorksheetFunction.CountA(ws_thold.Range("AK1:AK8"))
scol = 13 '14, 15, 16
srccol = 1 '2-8
srvc_drow = Application.WorksheetFunction.Match("ADD", .Columns(1)) + 1
If trigger_cancel = False Then
For L1 = 1 To srvcs_no
If srvc_drow > 32 Then 'add row
srvc_drow = srvc_drow + 1
MsgBox "Not enough room. Row added at " & svc_lrow + 1, , "UNTESTED"
Stop
.Range("A" & srvc_drow & ":R" & srvc_drow).Insert Shift:=xlDown
End If
With .Range("H" & srvc_drow & ":Q" & srvc_drow)
.Cells.Value = ""
.Cells.Interior.Color = RGB(166, 166, 166)
.Cells.locked = True
End With
If L1 = 5 Then
scol = scol - 4
End If
Set rng_cpy = ws_master.Range("A" & srow & ":G" & srow)
rng_cpy.Copy ws_master.Range("A" & srvc_drow)
With .Cells(srvc_drow, scol)
.Value = ws_thold.Cells(srccol, 39)
.Interior.ColorIndex = 0
End With
If ws_thold.Cells(srccol, 36) = "RLN" Then
d1 = "Reline"
Else
d1 = "Change"
End If
dmsg = d1 & " " & ws_thold.Cells(srccol, 37) & "-" & ws_thold.Cells(srccol, 38)
With .Cells(srvc_drow, 2)
.Font.Size = 6
.Font.Color = vbBlack
.Font.Bold = True
.Value = dmsg
.HorizontalAlignment = xlCenter
End With
'added for pda service group sort
With .Cells(srvc_drow, 18)
.Value = ws_thold.Cells(srccol, 43)
.Font.Size = 6
.Font.Color = RGB(229, 242, 251)
End With
.Rows(srvc_drow).AutoFit
.Rows(srvc_drow).Cells.locked = True
.Range(.Cells(srvc_drow, 1), .Cells(srvc_drow, 17)).VerticalAlignment = xlCenter
scol = scol + 1
srccol = srccol + 1
srvc_drow = srvc_drow + 1
Next L1
Else 'cancel = true
crid = ws_master.Cells(tmrow, 1)
rng_svcupr = Application.WorksheetFunction.Match("ADD", .Columns(1)) + 1
rng_svclwr = Application.WorksheetFunction.Match("Facility Maintenance Activities", .Columns(1)) - 3
rta = 0
For hcrus = rng_svclwr To rng_svcupr Step -1
If .Cells(hcrus, 1) = crid Then 'eliminate pda services matching RID
.Range("A" & hcrus & ":Q" & hcrus).Delete Shift:=xlUp
rta = rta + 1
End If
Next hcrus
'add empty rows to top up loss
rng_svcupr = 12
rng_svclwr = Application.WorksheetFunction.Match("Facility Maintenance Activities", .Columns(1)) - 2
rta = rng_svclwr - rng_svcupr
If rta < 21 Then 'top up needed
lastrow = .Cells(.Rows.Count, .Range("A12:A" & rng_svclwr)).End(xlUp).Row
rta = 21 - rta
For L2 = 1 To rta
.Range("A" & lastrow & ":Q" & lastrow).Insert Shift:=xlDown
Next L2
End If
'now add back the rows
trigger_cancel = False
bupdate_srvcpda trigger_cancel
End If
.Protect
mbevents = True
End With
Application.ScreenUpdating = True
End Sub