excel - 突出显示基于 pf 列标准的行 VBA
问题描述
我正在尝试编写一个 VBA 脚本来比较两个 = 行,并让电子表格仅在满足某些条件时才突出显示重复的行,例如(行的值,列 a = 第 1 行的值,列)和行的值, b 列 > 第 1 行的值,b 列)然后 b.font.color 列中较大值的整行 = vbRed。
这是我正在运行的表格的一部分...
这是我正在使用的代码...
Sub RemoveDuplicates()
Dim i As Long, R As Long
'Dim DeviceName As Range, SerialNumber As Range, LastContact As Range
Application.ScreenUpdating = False
R = Cells(Rows.Count, 1).End(xlUp).Row
'Set DeviceName = Columns(2)
'Set SerialNumber = Columns(3)
'Set LastContact = Columns(7)
For i = R To 2 Step -1
'If Cells(i, "F").Value > Cells(i - 1, "F").Value Then
'Code above doesn't work
If Cells(i, 3).Value = Cells(i - 1, 3).Value And Cells(i, 2).Value = Cells(i - 1, 2).Value Then
'If Cells(i, 3).Value = Cells(i - 1, 3).Value And Cells(i, 2).Value = Cells(i - 1, 2).Value And Cells(i, 5).Value > Cells(i - 1, 5).Value Then
'Code above doesn't work
Cells(i, 1).EntireRow.Font.Color = vbRed
End If
Next i
Application.ScreenUpdating = True
End Sub
我可以让重复项突出显示,但是当我尝试引入大于检查时,系统会出现问题。
解决方案
尝试条件格式规则。
With worksheets("sheet1").usedrange.offset(1, 0).entirerow
.FormatConditions.Delete
With .FormatConditions.Add(Type:=xlExpression, Formula1:="=and($a2=$a1, $b2=$b1, $f2>$f1)")
.font.Color = vbRed
End With
End With
推荐阅读
- reactjs - 使用 Nginx 刷新页面显示 404 错误
- azure - 在 powershell 中使用 get-Credentials 创建 azure secret
- java - 在 Windows 10 上双击 Eclipse 安装程序可执行文件 (eclipse-inst-jre-win64.exe) 后没有任何反应
- node.js - 处理快递申请中未处理的承诺拒绝
- c# - Azure.Storage.Blobs:找不到有效的帐户信息组合
- python - 将一组数据(URLS)放入一个空的数据框 Python Pandas
- angular - Angular Material Date Picker 不能动态命名(angular 9 - latest)
- python - 定时器中断发送数据micropython
- javascript - 使用偏移量的 Javascript API 获取循环
- flutter - TypeError: Cannot read properties of undefined (reading 'app') (Flutter web app)