If 1st 3 Digits of Column A match First 3 Digits Of Column B highlight both cell with a color

Pankti

New Member
Joined
Jun 28, 2024
Messages
7
Office Version
  1. 2013
I have a sheet with many numbers, and manually finding matching numbers is hard, so I want a solution to this.
If 1st 3 Digits of Column A match the First 3 Digits Of Column B highlight both cells with a color.
something like this:

AB
1​
111.454564
2​
34532111.75
3​
5655435
in this example, A1 and B2 should have the same color fill or the same color text.
something that visually tells me these numbers are a match.

would appreciate the help
thank you
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Pankti, try this (code to a module)
VBA Code:
Sub Highlight()
Dim i As Long, j As Long, r As Long

r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To r          'if there's no headline start with 1
    For j = 2 To r
        If Left(Cells(i, 1), 3) = Left(Cells(j, 2), 3) Then
            Cells(i, 1).Interior.ColorIndex = 6
            Cells(j, 2).Interior.ColorIndex = 6
        End If
    Next j
Next i

End Sub

Have fun
Senior Newbie
 
Upvote 0
This second version is a little bit more multi colored ;) and the "couples" are easier to find: sam value = same color

VBA Code:
Sub Highlight()
Dim i As Long, j As Long, l As Long
Dim r As Integer, g As Integer, b As Integer

l = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

r = 1: g = 85: b = 170
For i = 2 To l
    For j = 2 To l
        If Left(Cells(i, 1), 3) = Left(Cells(j, 2), 3) Then
            Cells(i, 1).Interior.Color = RGB(r, g, b)
            Cells(j, 2).Interior.Color = RGB(r, g, b)
        End If
    Next j
    r = r + 40
    If r > 250 Then
        r = r - 250
    End If
    g = g + 40
    If g > 250 Then
        g = g - 250
    End If
    b = b + 40
    If b > 250 Then
        b = b - 250
    End If
Next i

End Sub

Sub Reset()
ActiveSheet.Cells.Interior.Color = xlNone
End Sub

Have fun!
 
Last edited:
Upvote 0
Conditional Formatting.
1) Select A2:A100 Formula:= =AND(A2<>"",ISNUMBER(MATCH(LEFT(A2,3)&"*",B$2:B$100,0)))
2) Select B2:B100 Formula:= =AND(B2<>"",ISNUMBER(MATCH(LEFT(B2,3)&"*",A$2:A$100&"",0)))
 
Upvote 0
What happens if you have 123.45 in column A and 12.345 in column B? Would this be a match?
 
Upvote 0
Hi mumps
in my VBA version it would not be a match, because 123 and 12. is not equal.
 
Upvote 0
No need for an apology. :) We'll wait and see.
 
Upvote 0
This second version is a little bit more multi colored ;) and the "couples" are easier to find: sam value = same color

VBA Code:
Sub Highlight()
Dim i As Long, j As Long, l As Long
Dim r As Integer, g As Integer, b As Integer

l = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

r = 1: g = 85: b = 170
For i = 2 To l
    For j = 2 To l
        If Left(Cells(i, 1), 3) = Left(Cells(j, 2), 3) Then
            Cells(i, 1).Interior.Color = RGB(r, g, b)
            Cells(j, 2).Interior.Color = RGB(r, g, b)
        End If
    Next j
    r = r + 40
    If r > 250 Then
        r = r - 250
    End If
    g = g + 40
    If g > 250 Then
        g = g - 250
    End If
    b = b + 40
    If b > 250 Then
        b = b - 250
    End If
Next i

End Sub

Sub Reset()
ActiveSheet.Cells.Interior.Color = xlNone
End Sub

Have fun!
sorry, but I am new to all these formula things in Excel.
can you help me where to apply this code in Excel?
or can you apply it to my sheet for my understanding?
thank you

Book1
AB
1235.42445.63
2489.46376.53
3295.56490.05
4589.59892.3
51246.53115.63
6345.34235.33
7376.63905.54
8112.051246.53
9892.3165.99
10115.43454.35
Sheet1
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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