How to highlight row if same person has two different plan names

kmsprague

New Member
Joined
Nov 14, 2022
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I'm trying to highlight a row if a person has two different types of HSA plan. The list has other plan names, so I'm unable to use a unique highlight rule in conditional formatting. I've tried =COUNTIFS($A$2:$A$3000,$A3,$C$2:$C$3000,"*HSA - F*",$C$2:$C$3000,"*HSA - EE*") but it didn't work. I'm sure I'm missing something simple, but basically, I just want to have a formula that looks for the person's employee number in column A and then highlights if they have both types of HSA plans listed in column C. All help is greatly appreciated!!

Book2
ABC
1Employee NumberEmployee NamePlan Name
212345Smith, JohnHSA - Family
367890Smith, JohnHSA - EE Only
Sheet1
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I'm unsure how to highlight the rows without resorting to VBA code.

You could place this formula into a column and it will indicate the number of plans an employee has:

Excel Formula:
=IF(COUNTIFS(A:A,A2,C:C,"HSA - Family")>0,IF(COUNTIFS(A:A,A2,C:C,"HSA - EE Only")>0,"Two Plans","One Plan"),"No Plan")


If you don't mind using VBA, this might accomplish what you are looking to do:

VBA Code:
Sub Highligh_2HSA()
    Dim rngCell As Range
    Dim rngCurrentCell As Range
    Dim lRow As Long
    Dim sEmployee As String
    
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For Each rngCell In Range("A2:A" & lRow)
        sEmployee = rngCell.Value
        
        For Each rngCurrentCell In Range("A2:A" & lRow)
            If sEmployee = rngCurrentCell.Value And rngCurrentCell.Offset(0, 2) <> rngCell.Offset(0, 2) Then
                rngCell.EntireRow.Interior.ColorIndex = 6
                rngCurrentCell.EntireRow.Interior.ColorIndex = 6
            End If
        Next rngCurrentCell
    Next rngCell
End Sub
 
Upvote 0
How about
Excel Formula:
=AND(COUNTIFS($A$2:$A$3000,$A3,$C$2:$C$3000,"*HSA - F*"),COUNTIFS($A$2:$A$3000,$A3,$C$2:$C$3000,"*HSA - EE*"))
 
Upvote 0
Solution
How about
Excel Formula:
=AND(COUNTIFS($A$2:$A$3000,$A3,$C$2:$C$3000,"*HSA - F*"),COUNTIFS($A$2:$A$3000,$A3,$C$2:$C$3000,"*HSA - EE*"))
Thank you so very much!! Entering this into conditional formatting did the trick!
 
Upvote 0
I'm unsure how to highlight the rows without resorting to VBA code.

You could place this formula into a column and it will indicate the number of plans an employee has:

Excel Formula:
=IF(COUNTIFS(A:A,A2,C:C,"HSA - Family")>0,IF(COUNTIFS(A:A,A2,C:C,"HSA - EE Only")>0,"Two Plans","One Plan"),"No Plan")


If you don't mind using VBA, this might accomplish what you are looking to do:

VBA Code:
Sub Highligh_2HSA()
    Dim rngCell As Range
    Dim rngCurrentCell As Range
    Dim lRow As Long
    Dim sEmployee As String
   
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
   
    For Each rngCell In Range("A2:A" & lRow)
        sEmployee = rngCell.Value
       
        For Each rngCurrentCell In Range("A2:A" & lRow)
            If sEmployee = rngCurrentCell.Value And rngCurrentCell.Offset(0, 2) <> rngCell.Offset(0, 2) Then
                rngCell.EntireRow.Interior.ColorIndex = 6
                rngCurrentCell.EntireRow.Interior.ColorIndex = 6
            End If
        Next rngCurrentCell
    Next rngCell
End Sub
Thank you so much! I tried this and it looked like it highlighted the cells that didn't contain HSA. I'm not well versed in VBA, so I don't know how to fix it.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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