+ Reply to Thread
Results 1 to 4 of 4

Find non repeated characters in a string

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    27

    Find non repeated characters in a string

    Hi,

    I am trying to find the non repeated characters in a string.

    For example I have two strings ABCA and ABCD. I want to be able to add to the first string the characters missing from the second string without removing repeated character in the fist string. Result: ABCAD

    Many Thanks,´
    Maria

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Find non repeated characters in a string

    Hi
    maybe so
    Sub ttt()
    Dim i&, s1$, s2$
    s1 = "ABCA"
    s2 = "ABCD"
    For i = 1 To Len(s2)
        If InStr(s1, Mid(s2, i, 1)) = 0 Then s1 = s1 & Mid(s2, i, 1)
    Next i
    MsgBox s1
    End Sub

  3. #3
    Registered User
    Join Date
    05-08-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    27

    Re: Find non repeated characters in a string

    Nilem,

    It worked! very simple and effective.

    Thank you!

  4. #4
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: Find non repeated characters in a string

    Good time of day, Maria!

    Please check the attachment. User Defined Function used, macro must be allowed.

    Function Rio_Join$(StrA$, StrB$)
        Dim i&, j&, k&, StrC$
        Rio_Join = StrA
        For j = 1 To Len(StrB)
            k = 0
            For i = 1 To Len(Rio_Join)
                StrC = Mid(StrB, j, 1)
                If Mid(Rio_Join, i, 1) = StrC Then
                    k = 1
                    Exit For
                End If
            Next i
            If k = 0 Then Rio_Join = Rio_Join & StrC
        Next j
    End Function
    Attached Files Attached Files
    Best wishes and have a nice day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find the position of various characters in string
    By Hein in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-11-2014, 12:12 PM
  2. [SOLVED] Find All Characters After Last letter in String
    By Tellm in forum Excel General
    Replies: 4
    Last Post: 09-14-2012, 08:51 PM
  3. Find last repeated character position from a text string
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2011, 02:14 PM
  4. Find/Replace Characters in a string
    By Light Pail in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2010, 08:08 PM
  5. [SOLVED] find characters in text string
    By JAYB in forum Excel General
    Replies: 2
    Last Post: 09-02-2005, 03:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1