• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 52
  • Last Modified:

How to make sure there are no duplicate added to a string

After calling this function I would like to know how to make sure duplicate entries don't go in.

Function getEmailString(ByVal Rng As Range) As String
Dim Cell As Range
Dim Str As String
For Each Cell In Rng
    If Cell <> "" Then
        If Str = "" Then
            Str = Cell.Value
        Else
            Str = Str & ";" & Cell.Value
        End If
    End If
Next Cell
getEmailString = Str
End Function
0
SiHodgy007
Asked:
SiHodgy007
  • 2
1 Solution
 
NorieVBA ExpertCommented:
Try this.
Function getEmailString(ByVal Rng As Range) As String
Dim Cell As Range
Dim Str As String

    For Each Cell In Rng
        If Cell <> "" Then
            If Str = "" Then
                Str = Cell.Value
            Else
                If InStr(Str, Cell.Value) = 0 Then
                    Str = Str & ";" & Cell.Value
                End If
            End If
        End If
    Next Cell
    
    getEmailString = Str
    
End Function

Open in new window

0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I provided the same function in your last question. :)
0
 
SiHodgy007Author Commented:
I know I opened this as instructed before you answered and couldn't close it
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
No problem then. I thought the function didn't work for you so you posted the same question again. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now