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
 
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)))
sorry, but I am new to all these formula things in Excel.
can you help me apply this formula in Excel? because it's not working. I may be applying it incorrectly.
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

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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
hey thank you so much
i got it. found the way.
thank you sooooo much :)
 
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!
hey, this works perfectly with 2 columns. but in actual I have columns from A to L
how can I modify this?
kindly guide

thank you
 
Upvote 0
If you want then different colors,

VBA
Code:
Sub test()
    Dim a, e, i&, ii&, s$, n&, clr, dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    clr = Application.Trim(Array(3, 4, 5, 6, 8, 10, 11, 13, 14, 15, 16, 18, 21, _
                22, 24, 25, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51))
    With Intersect(Columns("a:l"), ActiveSheet.UsedRange)
        .Interior.ColorIndex = xlNone
        a = .Value
        For i = 1 To UBound(a, 1)
            For ii = 1 To UBound(a, 2)
                s = Left(a(i, ii), 3)
                If Not dic.exists(s) Then
                    Set dic(s) = .Cells(i, ii)
                Else
                    Set dic(s) = Union(dic(s), .Cells(i, ii))
                End If
            Next
        Next
    End With
    For Each e In dic
        If dic(e).Cells.Count > 1 Then
            n = n + 1
            If n > UBound(clr) Then n = 1
            dic(e).Interior.ColorIndex = clr(n)
        End If
    Next
End Sub
 
Upvote 0
What means A to L? Do you need the references for A&B, C&D or A or B or C & somewhere?

And - what detail is next? Please ask a full question, not step by step. That makes helping much easier.

I only can guess, but may be it's all about this question? How to highlight values with similar first three characters in a range A1:Lx
 
Upvote 0
What means A to L? Do you need the references for A&B, C&D or A or B or C & somewhere?

And - what detail is next? Please ask a full question, not step by step. That makes helping much easier.

I only can guess, but may be it's all about this question? How to highlight values with similar first three characters in a range A1:Lx
I am sorry if I was not clear at the beginning.

please check the attached image. this is how my sheet looks.

and I have to find matching numbers manually. so the idea is if anytime 2 numbers have the same first 3 digits they are highlighted in some color.
Finding some code that applies to the whole sheet would be great. as columns in the sheet may shift sometimes.
I hope now my question is more clear. I don't know if this is simple or more complex.
it would be great if you could help.
thank you so much.
Screenshot (190).png
 
Upvote 0
Hi Pankti,

this pic is nice but not helpful or do you really aspect, that we copy it line by line to an own sheet? Please help with a real sheet for testing a universal routine over all used range. thx
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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