Sub TIMESTATUS_SHEET1()
Dim C As Range
Dim strng As String
Application.Calculation = xlCalculationManual
With Sheet1 '<--| reference your sheet
For Each C In .Range("J:J").SpecialCells(xlCellTypeConstants, xlNumbers) '<--| loop through its column J not empty cells with numbers only
Select Case C.Value - .Cells(C.Row, "G").Value '<--| check the difference between curent column "J" cell and its corresponding one i column "G" against following cases
Case Is > 0 '<--| if difference >0
strng = "DELAY"
Case Is < 0 '<--| if difference <0
strng = "EARLY"
Case Else '<--| esle (i.e. if difference =0)
strng = "ON TIME"
End Select
If .Cells(C.Row, "K").Value = "Completed" Then
.Cells(C.Row, "L").Value = strng '<--| write down the value
Else: .Cells(C.Row, "L").Value = ""
End If
Next
Application.Calculation = xlCalculationAutomatic
End With
end sub
一位不错的用户在这里给了我上面的代码 - 我的问题是,当我在J列中输入日期值并且单词&#34;已完成&#34;时,我希望这会自动更新我的工作表。在&#34; K&#34;。
如果我删除了Application.Calculation = xlCalculationManual
,那么Excel不会停止计算,但我已经删除了影响相关单元格的所有其他代码。如果我保留它,我必须手动运行代码。我也尝试将它放在模块中并使用调用module.sub()
,但仍然遇到了同样的问题。