If it is already there, does it matter if it overwrites it? Replacing A with A is the same as replacing B with A.
Or are you asking to write in the next columns as per this event code?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastcol
If Target.Address = "$B$5" Then
With Worksheets("Sheet2")
If IsError(Application.Match(Target.Value, .Rows(5), 0)) Then
If .Range("A5").Value = "" Then
.Range("A5").Value = Target.Value
Else
lastcol = .Cells(5, .Columns.Count).End(xlToLeft).Column
.Cells(5, lastcol + 1).Value = Target.Value
End If
End If
End With
End If
End Sub