Dim not_done As Integer
Private Sub Worksheet_Activate()
'MsgBox ("oo")
not_done = 0
For col1 = 24 To 1519 Step col1 + 1
Call changeColor("AB", col1 & "")
Call changeColor("AC", col1 & "")
Call changeColor("AD", col1 & "")
Call changeColor("AE", col1 & "")
Call changeColor("AF", col1 & "")
Call changeColor("AG", col1 & "")
Call changeHeaderBackgroundColor(col1)
Next col1
Call done_result
End Sub
Sub changeColor(row, col)
If Range(row + col).Interior.ColorIndex = 3 And (Range(row + col).Value <> "" And Range(row + col).Value <> " ") Then
Range(row + col).Interior.ColorIndex = Range("AH" + col).Interior.ColorIndex
not_done = not_done - 1
End If
If Range("AH" + col).Value = "-" And (Range(row + col).Value = "" Or Range(row + col).Value = " ") Then
Range(row + col).Interior.ColorIndex = 3
not_done = not_done + 1
End If
End Sub
Sub changeHeaderBackgroundColor(cell)
'MsgBox Range("H" & cell).Value = " 日付を入力する"
If Range("H" & cell).Value = " 日付を入力する" And (Range("G" & cell).Value = "" Or Range("G" & cell).Value = " ") Then
'MsgBox "change color"
Range("G" & cell).Interior.ColorIndex = 3
not_done = not_done + 1
ElseIf Range("G" & cell).Interior.ColorIndex = 3 Then
'MsgBox "back color"
Range("G" & cell).Interior.ColorIndex = 0
not_done = not_done - 1
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' Call changeColor(Target.row & "", Target.Column & "")
'Call done_result
'MsgBox (Target.Columns.Column & " " & Target.Columns.row)
If TypeName(Target.Value) = "String" Then
If Target.Value = " " Then
Target.Value = Date & ""
'Target.FormatConditions =
clipstring = Cells(Target.Cells.row, "E") & "(" & Cells(Target.Cells.row, "G") & ")"
'MsgBox clipstring 'test already is success
Cells(3, "G") = clipstring
End If
If Target.Value = "," Then
Target.Value = "不可"
End If
Else
'target.Cells.
' MsgBox "qing不要xuan中多行操作!"
End If
If Target.Columns.Column = 28 Then
Call changeColor("AB", "" & Target.Columns.row)
Call done_result
ElseIf Target.Columns.Column = 29 Then
Call changeColor("AC", "" & Target.Columns.row)
Call done_result
ElseIf Target.Columns.Column = 30 Then
Call changeColor("AD", "" & Target.Columns.row)
Call done_result
ElseIf Target.Columns.Column = 31 Then
Call changeColor("AE", "" & Target.Columns.row)
Call done_result
ElseIf Target.Columns.Column = 32 Then
Call changeColor("AF", "" & Target.Columns.row)
Call done_result
ElseIf Target.Columns.Column = 7 And Target.Columns.row <> 6 Then
'MsgBox "goto header"
changeHeaderBackgroundColor (Target.Columns.row)
Call done_result
End If
End Sub
Sub done_result()
If (done + not_done) <> 0 Then
result = not_done
Range("G6").Value = "沒有做完的數量(the number not done is):" & result
Range("G6").Font.ColorIndex = 3
Range("G6:R6").Interior.ColorIndex = 5
End If
End Sub
Excel VBA 代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.