Private Sub Command1_Click() Dim a, b, y, c As String Dim x a = "1,2," b = "1,2,3,4," x = Split(a, ",") For i = 0 To UBound(x) y = x(i) If InStr(1, b, x(i)) <> 0 Then c = c + "," + x(i) End If Next Debug.Print c End Sub
Dim a(2),b,c c = "" a(1) = "1" a(2) = "3" b="1,2,3,4," If Instr(b,a(1)) > 0 Then Replace(b,a(1) ,"") c = b ElseIf Instr(c,a(2)) > 0 Then Replace(c,a(2) ,"") End If MsgBox c