我有一个检查特定列的代码。如果该特定列(第21列)为FALSE,那么我想仅为该特定行中存在错误的第8,9和10列中的单元格着色。
For i = 9 To LastRow
If Sheets("Test").Cells(i, 21).Value = "False" Then
Sheets("Test").Cells(i, 8:10).Font.Color = RGB(255, 0, 0)
End If
Next i
这不起作用。有没有办法在一行中执行此操作,而不是一次为每个单元格着色?
由于
答案 0 :(得分:2)
要修改此代码,请更新此行: <script src="{{url_for('static', filename='bundle{}.js'.format(version))}}"></script>
ws.Range(ws.Cells(r, 8), ws.Cells(r, 10)).Font.Color = vbRed
为了更快地使用Option Explicit
Public Sub ShowFalse()
Dim ws As Worksheet, lr As Long, r As Long
Set ws = ThisWorkbook.Worksheets("Test")
lr = ws.Cells(ws.Rows.Count, 21).End(xlUp).Row
If lr > 8 Then
Application.ScreenUpdating = False
For r = 9 To lr
If Not IsError(ws.Cells(r, 21)) Then
If ws.Cells(r, 21).Value = False Then
ws.Range(ws.Cells(r, 8), ws.Cells(r, 10)).Font.Color = vbRed
End If
End If
Next
Application.ScreenUpdating = True
End If
End Sub
AutoFilter
答案 1 :(得分:2)