Sub test()
Dim chaine As String
chaine = "Q484Q487Q588Q254"
MsgBox Replace_2d_occ(chaine, "X") 'replace le 2d caracteres identique au premier de la chaine
chaine = "Q484Q487Q588Q254"
MsgBox Replace_2d_occ(chaine, "X", True) 'replace tout les caracteres identiques au premier de la chaine
End Sub
Function Replace_2d_occ(chaine As String, char As String, Optional Alloccurence As Boolean)
If Not Alloccurence Then
If InStr(Mid(chaine, 2), Left(chaine, 1)) > 0 Then Mid(chaine, InStr(2, chaine, Left(chaine, 1)), 1) = char
Else
chaine = Left(chaine, 1) & Mid(Replace(chaine, Left(chaine, 1), char, 2), 2)
End If
Replace_2d_occ = chaine
End Function