Conditional formatting of row - Macro

Hello everyone,
I have a workbook with different worksheet. I want to come up with a macro that highlights and bold the rows that has 'Terminate' or 'Term' in Column C and don't have N/A or have Blank in Column J. Should apply to all worksheet. Any help will be appreciated.

Thanks-

Quick Google got me but I also need help with additional logic.

With Cells
    .FormatConditions.Add Type:=xlExpression, Formula1:= _
      "=($C1=""Terminate"")"
    With .FormatConditions(.FormatConditions.Count)
        .SetFirstPriority
        With .Interior
            .PatternColorIndex = xlAutomatic
            .Color = 7405514
            .TintAndShade = 0
        End With
        StopIfTrue = False
    End With
Milind AgarwalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this....
Sub SetConditionalFormatting()
Dim ws As Worksheet
Dim lr As Long
For Each ws In Worksheets
    lr = ws.Cells(Rows.Count, "C").End(xlUp).Row
    With ws.Range("A1:J" & lr)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
          "=AND($C1<>"""",ISNUMBER(SEARCH(""Term*"",$C1)),$J1<>"""",$J1<>""NA"")"
        .FormatConditions(1).Interior.Color = 7405514
        .FormatConditions(1).Font.Bold = True
    End With
Next ws
End Sub

Open in new window

Milind AgarwalAuthor Commented:
Hi, Its not doing the job exactly. It does highlight and bold the rows. But the rows that are highlighted don't have 'Term'  in column C and ' ' or 'N/A' in column J. Attaching a screen shot
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
No screen shot attached.
In fact it would be helpful if you upload a dummy workbook with Before and After sheet instead of attaching screen shot where in After sheet, show the desired output manually.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Milind AgarwalAuthor Commented:
Just uploaded a file. You could see anything other than N/A in column J is getting highlighted for Termination or term in Column C
Template_V1.xlsx
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
The code is working perfectly after making a change that is col. J contains N/A instead of NA as per your first post.

Use the following code and it will apply conditional formatting to all the rows where column C has "Term*" in it and col. J is not blank and does not contain N/A.
Sub SetConditionalFormatting()
Dim ws As Worksheet
Dim lr As Long
For Each ws In Worksheets
    lr = ws.Cells(Rows.Count, "C").End(xlUp).Row
    With ws.Range("A1:L" & lr)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
          "=AND($C1<>"""",ISNUMBER(SEARCH(""Term*"",$C1)),$J1<>"""",$J1<>""N/A"")"
        .FormatConditions(1).Interior.Color = 7405514
        .FormatConditions(1).Font.Bold = True
    End With
Next ws
End Sub

Open in new window

Milind AgarwalAuthor Commented:
Nope its not working. Even when I tried on the sample document.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
See the attached.
Is this not what you are trying to achieve?
Template_V1.xlsm
Milind AgarwalAuthor Commented:
Also the last row should be highlighted since it doesn't have N/A.  Just not sure why its not working.

Sub SetConditionalFormatting()
Dim ws As Worksheet
Dim lr As Long
For Each ws In Worksheets
    lr = ws.Cells(Rows.Count, "C").End(xlUp).Row
    With ws.Range("A1:L" & lr)
        .FormatConditions.Delete
        .FormatConditions.Add Type:=xlExpression, Formula1:= _
          "=AND($C1<>"""",ISNUMBER(SEARCH(""Term*"",$C1)),$J1<>""N/A"")"
        .FormatConditions(1).Interior.Color = 7405514
        .FormatConditions(1).Font.Bold = True
    End With
Next ws
End Sub
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Why should it highlight the row9? Since C9 is Temp but J9 is blank, so as per the rules it should not be highlighted.

Or I am missing something?
Milind AgarwalAuthor Commented:
Anything other than N/A in Column J should be highlighted when we have Term or Terminated in Column C. Modified the code U can find it below. Still doesn't work. Are we using a different version of excel mines 2007.

.FormatConditions.Add Type:=xlExpression, Formula1:= _
          "=AND($C1<>"""",ISNUMBER(SEARCH(""Term*"",$C1)),$J1<>""N/A"")"
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Well I changed the code and removed the part which checks for column J being blank and its highlighting the last row at my end. I don't have excel 2007 so not sure abut that.
But you may check the conditional formatting applied by the code in the Conditional Formatting --> Manage Rules and see what formula is being displayed as a rule for conditional formatting.

See the attached.
Template_V1.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.