Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Range("A2").Value = "ID" Then
Dim taskCnt As Long
Dim compCnt As Long
taskCnt = _
WorksheetFunction.CountA(Sh.Range("A3:A10000"))
compCnt = _
WorksheetFunction.CountIf(Sh.Range("D3:D10000"), "完了")
If taskCnt = compCnt Then
Sh.Name = Sh.Range("A1").Value
Else
Sh.Name = Sh.Range("A1").Value & _
"(" & (taskCnt - compCnt) & ")"
End If
End If
End Sub
では、コードについて解説していきます。
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Range("A2").Value = "ID" Then
'省略
End If
End Sub
Dim taskCnt As Long
Dim compCnt As Long
taskCnt = _
WorksheetFunction.CountA(Sh.Range("A3:A10000"))
compCnt = _
WorksheetFunction.CountIf(Sh.Range("D3:D10000"), "完了")
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Protect UserInterfaceOnly:=True
Dim r As Range
For Each r In Target
If r.Value <> "" Then
r.Locked = True
End If
Next r
End Sub
では、コードについて解説していきます。
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Protect UserInterfaceOnly:=True
'省略
End Sub