Highlight a row when they are equal on the adjacent cell VBA

rickjason

New Member
Joined
Jan 9, 2014
Messages
27
I have column A and Column B, how to highlight the cell when they are equal?

Sample and Expected Result

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Apple[/TD]
[TD]Banana[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Banana[/TD]
[TD]Apple[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Apple[/TD]
[TD]Apple[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Banana[/TD]
[TD]Apple[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


I tried to do this by doing Conditional Formatting, it works, however my rows are dynamic and blank cells bottom down after the last row with value are also captured.

Thanks.:confused:
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi rickjason,

Try this macro:

Code:
Option Explicit
Sub Macro5()

    Dim lngLastRow As Long
    Dim lngMyRow   As Long
    
    Application.ScreenUpdating = False
    
    lngLastRow = Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row
    
    For lngMyRow = 2 To lngLastRow
        If StrConv(Range("A" & lngMyRow), vbProperCase) = StrConv(Range("B" & lngMyRow), vbProperCase) Then
            Range("A" & lngMyRow & ":B" & lngMyRow).Font.Color = RGB(255, 0, 0)
        Else
            Range("A" & lngMyRow & ":B" & lngMyRow).Font.Color = RGB(0, 0, 0)
        End If
    Next lngMyRow
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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