我有以下代码检查Col P是否有某些文字,然后检查Col M是否有数字> 1,如果匹配则Col M中的数字将被着色。
我只想在这里添加一个条件:
- 另外检查Col O是否为文本"失败"如果匹配则检查Col P是否有所提到的字符串,然后检查Col M,如果COl M中的数字是> 3,然后在读取时将其着色(仅当它在Col P中有字符串时)或者不对其进行着色。
Sub Test()
Dim r As Long, LastRow As Long
Dim RemainingDay As Double '<--|
With Worksheets("Latency") '<--| reference worksheet "Latency"
LastRow = .Cells(.Rows.Count, "A").End(xlUp).row '<--| get row index of its column A last not empty cell
Application.ScreenUpdating = False
For r = 2 To LastRow
RemainingDay = 0 '<--|
If Weekday(.Range("K" & r).value, vbSaturday) > 2 Then '<--| having 'Weekday()' function starting from "Saturday",
Select Case True
Case InStr(.Range("P" & r).text, "Moved to SA (Compatibility Reduction)") > 0, _
InStr(.Range("P" & r).text, "Moved to SA (Failure)") > 0, _
InStr(Range("P" & r).text, "Gold framing") > 0
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 Select
End If
Next r
End With
End Sub
答案 0 :(得分:0)
您可以在2个选项中添加新的stack: []
recordData(value) {
stack.push(value)
......
}
:
选项1 :在新行中,If
之前(我的偏好)。
Select Case
选项2 :使用Sub Test()
Dim r As Long, LastRow As Long
Dim RemainingDay As Double '<--|
With Worksheets("Latency") '<--| reference worksheet "Latency"
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '<--| get row index of its column A last not empty cell
Application.ScreenUpdating = False
For r = 2 To LastRow
RemainingDay = 0 '<--|
If Weekday(.Range("K" & r).Value, vbSaturday) > 2 Then '<--| having 'Weekday()' function starting from "Saturday",
If .Range("o" & r).Value Like "Fail" Then '<-- ****** add the If here ******
Select Case True
Case InStr(.Range("P" & r).Text, "Moved to SA (Compatibility Reduction)") > 0, _
InStr(.Range("P" & r).Text, "Moved to SA (Failure)") > 0, _
InStr(Range("P" & r).Text, "Gold framing") > 0
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 Select
End If
End If
Next r
End With
End Sub
If
的现有行中
And