Results 1 to 2 of 2

Thread: Looping Thru Cell List??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Looping Thru Cell List??

    What would be the best approach to removing duplicates in a list with a definate seperator? Here is my issue: Cell "A1" has a list of numbers seperated by a "\". I know I can split the list by using SPLIT(expression,"\"). Now once the list is split I want to put only once instance of a number back in the cell i.e. Cell "A1" has the following numbers: "5\5\5\10\10\15\15\5\10" What I want to have is: "5\10\15"

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Looping Thru Cell List??

    I'm sure there are better ways, but this seems to work :

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim S As String
    5.     Dim Ar() As String
    6.     Dim i As Integer
    7.     Dim j As Integer
    8.     Dim sNew As String
    9.    
    10.     S = "5\5\5\10\10\15\15\5\10"
    11.    
    12.     Ar = Split(S, "\")
    13.    
    14.     For i = 0 To UBound(Ar)
    15.         For j = i + 1 To UBound(Ar)
    16.             If Ar(i) = Ar(j) Then
    17.                 Ar(j) = vbNullString
    18.             End If
    19.         Next
    20.     Next
    21.    
    22.     sNew = Join(Ar, "\")
    23.     Do While InStr(1, sNew, "\\")
    24.         sNew = Replace$(sNew, "\\", "\")
    25.     Loop
    26.    
    27.     MsgBox sNew
    28. End Sub

    I don't know if you are coding in VBA, but this is VB6. You can take the whole form load code and make it a function and use it in your VBA code just as easily.


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

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



Click Here to Expand Forum to Full Width