Private Sub Workbook_SheetActivate(ByVal sh As Object)
Dim thisNameRange As String
Dim endRow As Integer, summaryRow As Integer
Dim rList As String, destList As String
Dim rng As Range, protectionRange As Range
Dim tmpColumn As Integer
Dim dev As Boolean 'for debugging on/off
Application.ScreenUpdating = False
tmpColumn = 50
'MsgBox "Sheet " + sh.Name + " activated."
'dev = True
dev = False
If Not objWB Is Nothing Then
Set objWS = sh
Else
Module1.start False
End If
Set objWS = sh
Module1.activeDepartment = objWS.name
If Not dev Then
If Module1.isDepartment(objWS.name) Then
objWS.Unprotect passWrd
Protection.UnprotectTheseCells objWS
endRow = 3
thisNameRange = "res" + objWS.name
Set rng = objWS.Range(objWS.Cells(1, tmpColumn), objWS.Cells(1000, tmpColumn))
rng.ClearContents
objWB.Sheets("Own Resources").Range(thisNameRange).Copy objWS.Cells(endRow, tmpColumn)
'MsgBox "Hej"
Do While endRow < 1000 And StrComp(objWS.Cells(endRow, tmpColumn).Value, "") <> 0
endRow = endRow + 1
Loop
objWS.Cells(endRow, tmpColumn) = "Konsult"
objWS.Cells(endRow + 1, tmpColumn) = "Vakant"
objWS.Cells(endRow + 2, tmpColumn) = "Inlån"
rList = objWS.Range(objWS.Cells(3, tmpColumn), objWS.Cells(endRow + 2, tmpColumn)).Address
endRow = endRow - 1
Set rng = objWS.Cells.Find(what:="Summary", after:=objWS.Cells(1, 1), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
endRow = rng.Row - 1
summaryRow = rng.Row
Set rng = objWS.Range(objWS.Cells(5, 1), objWS.Cells(endRow, 1))
With rng
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & rList
.ShowError = True
End With
End With
Set rng = objWS.Range(objWS.Cells(5, 2), objWS.Cells(endRow, 2))
With rng
With .Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=projNames"
.ShowError = True
End With
End With
'Module1.updateTotal objWS
Module1.btnUpdateSummary
'objWS.Cells(1, 1).Select
End If
If StrComp(objWS.name, "Total A", vbTextCompare) = 0 Or _
StrComp(objWS.name, "Total AT", vbTextCompare) = 0 Or _
StrComp(objWS.name, "Total AL", vbTextCompare) = 0 Then
objWS.Unprotect passWrd
Protection.UnprotectTheseCells objWS
Module1.btnUpdateSummary
Set protectionRange = Module1.GetProtectionRange(objWS)
Protection.ProtectTheseCells protectionRange
objWS.Protect Password:=passWrd, UserInterfaceOnly:=True
End If
End If
Application.ScreenUpdating = True
Module1.objExcel.ActiveWindow.ScrollRow = 1
End Sub