Highlight only last ones that finds in end of the column

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,645
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000
Hi,

In the cells C3:K3 got 9 patterns with 3 different colour groups I need a VBA which Highlights only 9 patterns finds last in the column C as shown in the example with same format as C3:K3

Example....


Book1
ABCDEFGHIJKLM
1
2
31|11|X1|2X|1X|XX|22|12|X2|2
4
5
61 | 2
72 | 2
8X | 1
92 | 1
102 | 1
111 | 2
122 | 1
13X | X
142 | 1
151 | 1
161 | 2
171 | 1
18X | X
191 | 1
20X | 1
211 | X
22X | 2
232 | X
241 | 1
25X | 2
262 | 2
27X | X
282 | 1
291 | 2
301 | X
31X | 2
321 | 2
33X | 1
342 | X
35X | 1
36X | X
372 | 2
38
39
40
41
Sheet10


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about
Code:
Sub Kishan()
   Dim i As Long
   
   With CreateObject("scripting.dictionary")
      For i = 3 To 11
         .Item(Cells(3, i).Value) = Cells(3, i).Interior.Color
      Next i
      For i = Range("C" & Rows.Count).End(xlUp).Row To 6 Step -1
         If .exists(Cells(i, 3).Value) Then
            Cells(i, 3).Interior.Color = .Item(Cells(i, 3).Value)
            .Remove Cells(i, 3).Value
         End If
      Next i
   End With
End Sub
The values in C3:K3 of your example don't include spaces, but those in C6:C37 do. They need to be the same for this to work.
 
Upvote 0
Another way with the same comment as Fluff about spaces v No spaces.
I also assume that it is a mistake that you have cell C33 coloured and not C35?

Code:
Sub Highlight_Last()
  Dim c As Range, cFound As Range
  
  For Each c In Range("C3:K3")
    Set cFound = Range("C6:C37").Find(What:=c.Value, SearchDirection:=xlPrevious)
    If Not cFound Is Nothing Then cFound.Interior.Color = c.Interior.Color
  Next c
End Sub
 
Upvote 0
How about
Code:
Sub Kishan()
The values in C3:K3 of your example don't include spaces, but those in C6:C37 do. They need to be the same for this to work.
Hi, </SPAN></SPAN>Fluff, it is my fault I included the space in the header values in C3:K3 and code worked fine thank you so much for the help.</SPAN></SPAN>

Please can white font be added in it?
</SPAN>

Kind Regards
</SPAN></SPAN>
Kishan

Another way with the same comment as Fluff about spaces v No spaces.
I also assume that it is a mistake that you have cell C33 coloured and not C35?
Code:
Sub Highlight_Last()
Hi, </SPAN></SPAN>Peter_SSs, yes added a space in values C3:K3 code worked fine thank you for your help and observing yes I had a mistake C35 is correct to be coloured not C33 you are correct.</SPAN></SPAN>

Please can white font be added in it?
</SPAN>

Kind Regards
</SPAN></SPAN>
Kishan

</SPAN></SPAN></SPAN>
 
Last edited:
Upvote 0
How about
Code:
Sub Kishan()
   Dim i As Long
   
   With CreateObject("scripting.dictionary")
      For i = 3 To 11
         .Item(Cells(3, i).Value) = Cells(3, i).Interior.Color
      Next i
      For i = Range("C" & Rows.Count).End(xlUp).Row To 6 Step -1
         If .exists(Cells(i, 3).Value) Then
            Cells(i, 3).Interior.Color = .Item(Cells(i, 3).Value)
            Cells(i, 3).Font.Color = vbWhite
            .Remove Cells(i, 3).Value
         End If
      Next i
   End With
End Sub
 
Upvote 0
How about
Code:
Sub Kishan()
   Dim i As Long
   
   With CreateObject("scripting.dictionary")
      For i = 3 To 11
         .Item(Cells(3, i).Value) = Cells(3, i).Interior.Color
      Next i
      For i = Range("C" & Rows.Count).End(xlUp).Row To 6 Step -1
         If .exists(Cells(i, 3).Value) Then
            Cells(i, 3).Interior.Color = .Item(Cells(i, 3).Value)
            Cells(i, 3).Font.Color = vbWhite
            .Remove Cells(i, 3).Value
         End If
      Next i
   End With
End Sub
Fluff, that is great of you including quick a white font too it is just ideal. </SPAN></SPAN>
Thank you.
</SPAN></SPAN>

Kind Regards
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>

 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi, </SPAN></SPAN>Peter_SSs, yes added a space in values C3:K3 code worked fine thank you for your help and observing yes I had a mistake C35 is correct to be coloured not C33 you are correct.</SPAN></SPAN>

Please can white font be added in it?
</SPAN>

Kind Regards
</SPAN></SPAN>
Kishan

</SPAN></SPAN></SPAN>
Peter_SSs, I tried and it could be able to modified to add the white font it were easy to add in your code. And I hope it is done correctly.</SPAN></SPAN>
Code:
Sub Highlight_Last()
  Dim c As Range, cFound As Range
  
     Dim lngLastRow As Long
     lngLastRow = Cells(Rows.Count, "C").End(xlUp).Row
       
  For Each c In Range("C3:K3")
    Set cFound = Range("C6:C" & lngLastRow).Find(What:=c.Value, SearchDirection:=xlPrevious)
    If Not cFound Is Nothing Then cFound.Interior.Color = c.Interior.Color
    If Not cFound Is Nothing Then cFound.Font.Color = c.Font.Color
  Next c
End Sub
Kind Regards
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Last edited:
Upvote 0
You can simplify that slightly like
Code:
  For Each c In Range("C3:K3")
    Set cFound = Range("C6:C" & lngLastRow).Find(What:=c.Value, SearchDirection:=xlPrevious)
    If Not cFound Is Nothing Then
       cFound.Interior.Color = c.Interior.Color
       cFound.Font.Color = c.Font.Color
    End If
  Next c
 
Upvote 0
You can simplify that slightly like
Code:
  For Each c In Range("C3:K3")
    Set cFound = Range("C6:C" & lngLastRow).Find(What:=c.Value, SearchDirection:=xlPrevious)
    If Not cFound Is Nothing Then
       cFound.Interior.Color = c.Interior.Color
       cFound.Font.Color = c.Font.Color
    End If
  Next c
Fluff, that looks much better it worked fine thank you for making it simpler.</SPAN></SPAN>

Kind Regards
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,020
Members
448,543
Latest member
MartinLarkin

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