Excel VBA 代碼

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值