highlight numbers

kerm007

Active Member
Joined
Mar 16, 2019
Messages
250
Office Version
  1. 365
Platform
  1. Windows
hello
in a round robin match up to avoid certain match up i did that :

VBA Code:
 Set rng = Range("B5:F700")

    With rng
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,54)>0,COUNTIF($B5:$F5,9)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,3)>0,COUNTIF($B5:$F5,9)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,5)>0,COUNTIF($B5:$F5,6)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$G5,8)>0,COUNTIF($B5:$G5,10)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,8)>0,COUNTIF($B5:$F5,10H)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
    End With

End Sub


it work for certain but since i add this one :




VBA Code:
.FormatConditions.Add Type:=xlExpression, Formula1:= _

            "=AND(COUNTIF($B5:$F5,8)>0,COUNTIF($B5:$F5,10H)>0)"

        .FormatConditions(.FormatConditions.Count).SetFirstPriority

        With .FormatConditions(1).Interior

            .PatternColorIndex = xlAutomatic

            .Color = RGB(0, 128, 0)

            .TintAndShade = 0

        End With


it give me an error is it because the number have an H to it ?
Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
i test out and if there no H to the number it work
how can i make it work with the H ?
Thanks
 
Upvote 0
If the 10H is a text string in a cell then it needs to be in double quotes, if it is a cell reference then it needs to be H10
 
Upvote 0
hello i tries it like this :
VBA Code:
Sub MyFormat()

    Dim rng As Range
    Set rng = Range("B5:F700")

    With rng
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,54)>0,COUNTIF($B5:$F5,9)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,3)>0,COUNTIF($B5:$F5,9)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions(1).StopIfTrue = False
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$F5,5)>0,COUNTIF($B5:$F5,6)>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=AND(COUNTIF($B5:$G5,8)>0,COUNTIF($B5:$G5,"10H")>0)"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = RGB(0, 128, 0)
            .TintAndShade = 0
        End With
        
        
        .FormatConditions(1).StopIfTrue = False
    End With

End Sub

it failed on the 10H

Thanks
 
Upvote 0
You need double quotes as I stated
""10H""
 
Upvote 1
Solution

Forum statistics

Threads
1,215,079
Messages
6,123,000
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top