+ Reply to Thread
Results 1 to 2 of 2

no duplication please

  1. #1
    asmenut
    Guest

    no duplication please

    THanks for the help with the "List without Listbox" question sbmitted
    yesterday.

    Due to the simplified nature of the "list", if thought that a "Collection"
    would be sufficient. The problem is that i can't seem to get the "No
    duplication" aspect to function. Any idea as to what I am doing wrong (other
    than coding this myself )

    Private Sub CommandOK_Click()
    Dim NoDupes_test As New Collection
    Dim i As Integer
    Dim sStr

    On Error Resume Next
    NoDupes_test.Add Item:=sStr.Value, key:=sStr.Value
    On Error GoTo 0

    Select Case True
    Case CheckMachine.Value
    Range("A1").Value = "Marketing"
    If CheckMNew.Value = True Then
    NoDupes_test.Add "ProductManager"
    End If
    If CheckMFFF.Value = True Then
    NoDupes_test.Add "ProductManager"
    NoDupes_test.Add "Director of Engineering"
    End If
    If CheckMWarranty.Value = True Then
    NoDupes_test.Add "Director of Engineering"
    NoDupes_test.Add "Director of Service"
    NoDupes_test.Add "Quality Manager"
    End If
    If CheckMDisc.Value = True Then
    NoDupes_test.Add "ProductManager"
    End If
    'some or cases here
    End Select

    If NoDupes_test.Count > 0 Then
    For i = 1 To NoDupes_test.Count
    sStr = sStr & NoDupes_test(i) & vbLf
    Next i
    End If
    Range("A4").Value = sStr

    End Sub

  2. #2
    asmenut
    Guest

    Re: no duplication please

    thanks

    "Doug Glancy" wrote:

    > Each time you add an item to the collection you need to bracket it with the
    > two "On Error" statements and you need to specify a key. The error is
    > genererated when you try to add a duplicate key. Your On Error statements
    > tell Excel to ignore the error, the key is not added and you get your
    > intended result of no duplicates. So, something like this:
    >
    > If CheckMNew.Value = True Then
    > On Error Resume Next
    > NoDupes_test.Add Item:="ProductManager", Key = "ProductManager"
    > On Error GoTo 0
    > End If
    >
    > hth,
    >
    > Doug
    >
    > "asmenut" <[email protected]> wrote in message
    > news:[email protected]...
    > > THanks for the help with the "List without Listbox" question sbmitted
    > > yesterday.
    > >
    > > Due to the simplified nature of the "list", if thought that a "Collection"
    > > would be sufficient. The problem is that i can't seem to get the "No
    > > duplication" aspect to function. Any idea as to what I am doing wrong

    > (other
    > > than coding this myself )
    > >
    > > Private Sub CommandOK_Click()
    > > Dim NoDupes_test As New Collection
    > > Dim i As Integer
    > > Dim sStr
    > >
    > > On Error Resume Next
    > > NoDupes_test.Add Item:=sStr.Value, key:=sStr.Value
    > > On Error GoTo 0
    > >
    > > Select Case True
    > > Case CheckMachine.Value
    > > Range("A1").Value = "Marketing"
    > > If CheckMNew.Value = True Then
    > > NoDupes_test.Add "ProductManager"
    > > End If
    > > If CheckMFFF.Value = True Then
    > > NoDupes_test.Add "ProductManager"
    > > NoDupes_test.Add "Director of Engineering"
    > > End If
    > > If CheckMWarranty.Value = True Then
    > > NoDupes_test.Add "Director of Engineering"
    > > NoDupes_test.Add "Director of Service"
    > > NoDupes_test.Add "Quality Manager"
    > > End If
    > > If CheckMDisc.Value = True Then
    > > NoDupes_test.Add "ProductManager"
    > > End If
    > > 'some or cases here
    > > End Select
    > >
    > > If NoDupes_test.Count > 0 Then
    > > For i = 1 To NoDupes_test.Count
    > > sStr = sStr & NoDupes_test(i) & vbLf
    > > Next i
    > > End If
    > > Range("A4").Value = sStr
    > >
    > > End Sub

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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