數我有下面的代碼檢查山坳K代表「星期日」的日期和「時間」,並與上校M.減去剩餘時間和比較VBA
這是什麼代碼做數字比較? :
例如,如果Col K中的日期/時間是2/5/2017 18:00:00,它應該減去剩餘的剩餘時間,即一天中的0.6小時結束,col中的數字M.如果Col M中的值大於1,則減法後應突出顯示,或者如果減法後小於1,則應將其着色爲紅色。
問題:
- 的代碼並在紅色不變色,如果在山口M中的值是在1.5,1.6,1.7 etc..Only的範圍,如果超過> = 2時,它開始着色在紅色..我該如何解決這個問題?
當前有兩個過程定義爲通過和失敗。我如何結合這一點?
Sub MinusSunday() Dim r, LastRow, RemainingDay As Double LastRow = Range("M:O").Cells(Rows.Count, "A").End(xlUp).Row Application.ScreenUpdating = False For r = 2 To LastRow RemainingDay = 0 If Weekday(Range("K" & r).Value, vbSunday) = 1 Then RemainingDay = Round((24 - Format(TimeValue(Range("K" & r)), "h"))/24, 1) If InStr(1, Range("O" & r).Text, "Pass", vbTextCompare) > 0 Then If Range("M" & r) - RemainingDay >= 1 Then Range("M" & r).Cells.Font.ColorIndex = 3 Else Range("M" & r).Cells.Font.ColorIndex = 0 End If End If End If Next r For r = 2 To LastRow RemainingDay = 0 If Weekday(Range("K" & r).Value, vbSunday) = 1 Then RemainingDay = Round((24 - Format(TimeValue(Range("K" & r)), "h"))/24, 1) If InStr(1, Range("O" & r).Text, "Fail", vbTextCompare) > 0 Then If Range("M" & r) - RemainingDay >= 1 Then Range("M" & r).Cells.Font.ColorIndex = 3 Else Range("M" & r).Cells.Font.ColorIndex = 0 End If End If End If Next r End Sub
等一下,你說*'2/5/2017 18:00:00'剩下的時間,即0.6小時*? 6小時不是0.6小時,不是? –
即使「通過」或「失敗」,如果您想將列M中的單元格變爲紅色(如果當天還剩餘1小時以上),那麼@stack標記? –
我試圖瞭解'RemainingDay'的計算。它是什麼單位? M列中的究竟是什麼? Data和Calc的一個例子會很有用。 –