Color the range if multiple conditions satisfied

Mithunrnair

New Member
Joined
Nov 18, 2019
Messages
5
Need a help to highlight the respective cells, if a user (name) in rage A have an SIA and WU value in rage B.

The code I have, dosent work completely but some what give an idea where I am now.

VBA Code:
Sub HighlightCell ()

Dim cell As Range, rg As Range, rng As Range, cond1 As FormatCondition, cond2 As FormatCondition, cond3 As FormatCondition

Range("A1", Range("A2").End(xlDown)).Select
    Selection.Copy
    Range("F1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

 ActiveSheet.Range("F2").End(xlDown)).RemoveDuplicates Columns:=1, Header:=xlYes

Set rg = Range("B2", Range("B2").End(xlDown))
Set rng = Range("F2", Range("F2").End(xlDown))

For Each cell In rng
rg.FormatConditions.Delete

Set cond1 = rg.FormatConditions.Add(xlCellValue, xlEqual, "SIA")
Set cond2 = rg.FormatConditions.Add(xlCellValue, xlEqual, "WU")

'define the format applied for each conditional format

With cond1
.Interior.Color = vbGreen
.Font.Color = vbWhite
End With

With cond2
.Interior.Color = vbGreen
.Font.Color = vbWhite
End With

Next cell

End Sub

Any help really appreciated.... Thanks in advance
IMG-20191118-WA0001.jpg
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You do not need VBA to do this. It can be done with Conditional Formatting.
Just highlight columns A and B, and enter this Conditional Formatting formula:
Code:
=and(countifs($A:$A,$A1,$B:$B,"SIA")>0,countifs($A:$A,$A1,$B:$B,"WU")>0)
and choose your yellow highlighting option.

If you would VBA code to do this, you can turn on the VBA recorder, and record yourself applying this Conditional Formatting.
 
Upvote 0
How is the posted code not working?
 
Upvote 0
How is the posted code not working?
Thanks, I dont have deep knowledge in VBA, i am still on learning face.

The code will only highlight all the cells which have vale SIA and WU. But i need it to be highlighted in way that it showed in the image i added here.
 
Upvote 0
You do not need VBA to do this. It can be done with Conditional Formatting.
Just highlight columns A and B, and enter this Conditional Formatting formula:
Code:
=and(countifs($A:$A,$A1,$B:$B,"SIA")>0,countifs($A:$A,$A1,$B:$B,"WU")>0)
and choose your yellow highlighting option.

If you would VBA code to do this, you can turn on the VBA recorder, and record yourself applying this Conditional Formatting.
Thsnks, but it will highlight all the cell with values SIA and WU. I need only specific cells to be highlighted as the photo i added here.... for exg if Alex have SIA and WU his name should be highlighted.... if Bob have only SIA leave that record, if next pwrson have only WU leave him. And finally Don have SIA and WU he need to be highlighted.... like this it has to perform for each users in row A
 
Upvote 0
Thanks, but it will highlight all the cell with values SIA and WU. I need only specific cells to be highlighted as the photo i added here.... for exg if Alex have SIA and WU his name should be highlighted.... if Bob have only SIA leave that record, if next pwrson have only WU leave him. And finally Don have SIA and WU he need to be highlighted.... like this it has to perform for each users in row A
Thanks, it will partially solve my issue, because it will mark all of them as true, if it found the SIA and WU for a user.... (image attached) any other better solution expected.....
 

Attachments

  • IMG-20191118-WA0001.jpg
    IMG-20191118-WA0001.jpg
    41.3 KB · Views: 6
Upvote 0
So, are you saying that you only want to highlight the two records where the changeover in column B happens?
Is your data always sorted like that, by column A first, then by column B, or might the records be mixed?
 
Upvote 0
So, are you saying that you only want to highlight the two records where the changeover in column B happens?
Is your data always sorted like that, by column A first, then by column B, or might the records be mixed?
Yes, It will be always sorted in manner and yes I need to get a combinations of SIA and WU highlighted always for each users, if a user have only one combination it has to be highlighted and if a user have 4 entries 2 SIA and 2 WU then I need all those 4 to be highlighted.... i know it sounds bit complicated.... this is how i do this manually and on top of 3000 records I have to do this analyses everymonth....
 
Upvote 0
if a user have 4 entries 2 SIA and 2 WU then I need all those 4 to be highlighted....
Can you please post what that would look like, as that does not seem to mesh with the statement with how the data is to be sorted?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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