|
发表于 2023-7-8 09:25
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub ApplyConditionalFormatting()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' 设置工作表
Set ws = ThisWorkbook.Worksheets("Sheet1") ' 替换为您的工作表名称
' 获取最后一行
lastRow = ws.Cells(ws.Rows.Count, "F").End(xlUp).Row
' 循环遍历行
For i = 2 To lastRow ' 假设第一行是标题行,从第二行开始
' 检查条件并应用格式
If (ws.Range("F" & i).Value = "smoke" Or ws.Range("F" & i).Value = "strobe") And ws.Range("J" & i).Value <> "pass" And ws.Range("K" & i).Value <> "pass" Then
ws.Range("K" & i).Interior.Color = RGB(0, 255, 0) ' 将列K设为绿色
End If
If (ws.Range("F" & i).Value = "smoke" Or ws.Range("F" & i).Value = "strobe") And ws.Range("L" & i).Value <> "pass" And ws.Range("M" & i).Value <> "pass" Then
ws.Range("M" & i).Interior.Color = RGB(0, 255, 0) ' 将列M设为绿色
End If
If ws.Range("F" & i).Value = "therm" And ws.Range("J" & i).Value <> "pass" Then
ws.Range("K" & i).Interior.Color = RGB(0, 255, 0) ' 将列K设为绿色
End If
If ws.Range("F" & i).Value = "therm" And ws.Range("J" & i).Value <> "pass" And ws.Range("K" & i).Value <> "pass" Then
ws.Range("L" & i).Interior.Color = RGB(0, 255, 0) ' 将列L设为绿色
End If
If ws.Range("F" & i).Value = "therm" And ws.Range("J" & i).Value <> "pass" And ws.Range("K" & i).Value <> "pass" And ws.Range("L" & i).Value <> "pass" Then
ws.Range("M" & i).Interior.Color = RGB(0, 255, 0) ' 将列M设为绿色
End If
If ws.Range("F" & i).Value = "therm" And ws.Range("J" & i).Value <> "pass" And ws.Range("K" & i).Value <> "pass" And ws.Range("L" & i).Value <> "pass" And ws.Range("M" & i).Value <> "pass" Then
ws.Range("N" & i).Interior.Color = RGB(0, 255, 0) ' 将列N设为绿色
End If
If ws.Range("F" & i).Value = "mcp" And (ws.Range("J" & i).Value <> "pass" Or ws.Range("K" & i).Value <> "pass" Or ws.Range("L" & i).Value <> "pass" Or ws.Range("M" & i).Value <> "pass" Or ws.Range("N" & i).Value <> "pass") Then
ws.Range("J" & i & ":N" & i).Interior.Color = RGB(0, 255, 0) ' 将列J到N设为绿色
End If
Next i
' 清除选择
ws.Cells(1, 1).Select
End Sub |
|