Question: I'm trying to solve a problem in VBA and after a long time of browsing the web for solutions, I really hope someone is able to help me.  

It's actually not a very hard task, but with very little programming and VBA knowledge as a new learner, I hope I can find a useful tip or solution with the help of the community.

So my problem is as follows:

I have a table with 3 columns, the first is filled with a number to use as an ID. Column 2 and 3 have different values that needs to be compared:  

[![picture](https://i.stack.imgur.com/LdQZe.png)](https://i.stack.imgur.com/LdQZe.png)

What I'd like to do is select the range of column rows of column 2 and 3 based on the same ID. Once I have selected the relevant ranges of the columns, I want to compare if one name of column 2 matches one name of column 3.

So there is no need to have all names of the desired column ranges to match. One name match is enough. If a name matches, it should automatically fill in a new column "result" with 1 for match (0 for no match).

Do you have an idea, how I can select specific cells of a column based on an identifier?

```vb
    Dim ID_counter As Long
    ID_counter = 1

    If Cell.Value = ID_counter IN Range("Column1")
        Then Range("Column2").Select
        AND Range("Column3").Select
        WHERE ID_counter is the same

    In Column4 (If one Cell.Value IN Range("Column2-X:Column2-Y")
                IS IDENTICAL TO Range("Column3-X:Column3-Y"), return 1, else return 0

End Sub

```

Many thanks in advance for your help!

Answer: 
This works for your example so perhaps you can generalise it. The formula in D2 is

```
=IF(A2=A1,"",MAX(IF($A$2:$A$10=A2,COUNTIF($B$2:$B$10,$C$2:$C$10))))

```

and is an array formula so must be confirmed with CTRL, SHIFT and ENTER.

[![enter image description here](https://i.stack.imgur.com/fLGYI.png)](https://i.stack.imgur.com/fLGYI.png)
First enter this user defined function in a standard module:

```
Public Function zool(r1, r2, r3) As Integer
    Dim i As Long, v1 As Long, v2 As String
    Dim top As Long, bottom As Long

    zool = 0
    v1 = r1.Value
    top = r1.Row

    '   determine limits to check

    For i = top To 9999
        If v1 <> r1.Offset(i - top, 0).Value Then
            Exit For
        End If
    Next i
    bottom = i - 1

    For i = top To bottom
        v2 = Cells(i, "B").Value
            If v2 <> "" Then
                For j = top To bottom
                    If v2 = Cells(j, "C").Value Then zool = 1
                Next j
            End If
        Next i

End Function

```

Then in **D2** enter:

```
=IF(OR(A2="",A2=A1),"",zool(A2,B2,C2))

```

and copy downwards:

[![enter image description here](https://i.stack.imgur.com/oIGc6.png)](https://i.stack.imgur.com/oIGc6.png)

*(this assumes that the data has been sorted or organized by **ID** first)*