Another option: Use the Find method to see if the Street Name exists and whether or not the house number is different.
Basic Code:
Private Sub CommandButton1_Click()
Dim strStreet As String, Msg As String
Dim rFound As Range, rRng As Range
Dim lrow As Long, lHousenum As Long
lrow = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
lHousenum = Me.TextBox1.Value
Set rRng = Sheet1.Range("B2:B" & lrow) 'where to search for the value
strStreet = Me.TextBox2.Text
Msg = "The house number and street already exists - duplicate entries not permitted."
Set rFound = rRng.Find(strStreet, LookIn:=xlValues)
If Not rFound Is Nothing Then
Select Case rFound.Offset(0, -1).Value
Case Is = lHousenum
MsgBox (Msg), vbExclamation
Me.TextBox1.Value = vbNullString
Me.TextBox2.Value = vbNullString
Case Else
'code to write to sheet
End Select
End If
End Sub
Bookmarks