条件格式化VBA不突出显示工作表

时间:2015-07-08 15:17:44

标签: excel vba excel-vba

我对代码中的条件格式部分提出了一个简单的问题,

其余的代码完美无缺,但是当我到达条件格式化部分时,我想突出显示的行并不是。我希望根据copysheet区域中单元格H5上的值突出显示行。

单元格H5具有formala = MAX(IF(ISERROR(" L8:L2500,"",L8:2500"),其在范围L

有没有办法应用条件格式来搜索最大值?

Sub Search()

Dim vCrit As Variant
Dim filtersheet As Worksheet
Dim copysheet As Worksheet
Dim rngCrit As Range
Dim rngList As Range



Set filtersheet = Worksheets("Datalog")
Set copysheet = Worksheets("Line Inquiry")


filtersheet.Unprotect


Set rngCrit = filtersheet.Range("$A$7:$L$2500").CurrentRegion
Set rngList = copysheet.Range("B5")



vCrit = Sheets("Datalog").Range("O3")

copysheet.Range("A8:K2500").Clear


With filtersheet
rngCrit.AutoFilter _
Field:=3, _
Criteria1:=Application.Transpose(vCrit), _
Operator:=xlFilterValues



rngCrit.SpecialCells(xlCellTypeVisible).Copy
copysheet.Range("A7").PasteSpecial xlPasteFormulasAndNumberFormats
Application.CutCopyMode = False

Application.ScreenUpdating = False
filtersheet.AutoFilterMode = False


filtersheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

copysheet.Range("A8:L2500").FormatConditions.Delete

With copysheet.Range("$A8:$L8").FormatConditions.Add( _
Type:=xlExpression, _
Formula1:="=$H$5=$L8")
.Interior.Color = RGB(198, 239, 206)
.Font.Color = RGB(0, 97, 0)


    End With

End With

'returning to original sheet
copysheet.Range("B5").Select

End Sub

1 个答案:

答案 0 :(得分:1)

您可以在代码中进行格式化。这样的事情。

if somecondition then
    copysheet.Range("I" & lRow).Font.ColorIndex = 3
End if