【发布时间】:2021-04-10 14:03:36
【问题描述】:
如果填充了某些单元格,我正在尝试将规则应用于模板的列,然后格式将使用公式的值/地址。在这一点上我有点迷茫,因为其他一切都在正常工作,我没有收到任何错误。 QAcol 在用于填充这些单元格的代码中较早地生成。任何将工作表指定为条件格式范围的尝试都会导致对象定义错误,我不知道为什么。
Dim CFQcol As Integer
Dim j As Integer
wb.Sheets("QA Data").Activate
row = 0
col = 0
For CFQcol = 17 To QAcol
If IsEmpty(wb.Sheets("QA Data").Cells(3, CFQcol)) = False And InStr(wb.Sheets("QA Data").Cells(3, CFQcol).Value, "Repo") = 0 Then
j = 1
If IsEmpty(wb.Sheets("QA Data").Cells(4, CFQcol)) = False Then
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:=Cells(4, CFQcol).Address
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions(j).Font.Color = RGB(255, 0, 0)
j = j + 1
End If
If IsEmpty(wb.Sheets("QA Data").Cells(7, CFQcol)) = False Then
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:=Cells(7, CFQcol).Address
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions(j).Font.Color = RGB(0, 0, 200)
j = j + 1
End If
If IsEmpty(wb.Sheets("QA Data").Cells(5, CFQcol)) = False Then
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:=Cells(5, CFQcol).Address
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions(j).Font.Color = RGB(255, 0, 0)
j = j + 1
End If
If IsEmpty(wb.Sheets("QA Data").Cells(8, CFQcol)) = False Then
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:=Cells(8, CFQcol).Address
Range(Cells(11, CFQcol), Cells(10000, CFQcol)).FormatConditions(j).Font.Color = RGB(0, 0, 200)
End If
End If
Next
感谢您的帮助!
【问题讨论】:
-
您不需要将地址更改为亲戚吗? .地址(假,假)
标签: vba formatting conditional-statements