+ Reply to Thread
Results 1 to 2 of 2

Working with Listbox Duplicated values

Hybrid View

coreytroy Working with Listbox... 03-07-2013, 10:35 PM
coreytroy Re: Working with Listbox... 03-07-2013, 10:55 PM
  1. #1
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Lightbulb Working with Listbox Duplicated values

    Private Sub ListBox1_Click()
    Application.ScreenUpdating = False
    ListBox2.Clear
    Dim NoDupes As Collection
    On Error Resume Next
    LastCell = Worksheets("Data").Cells(Rows.Count, "B").End(xlUp).Row
    With ActiveWorkbook.Worksheets("Data")
    .Select
    Set NoDupes = New Collection
        For myrow = 1 To LastCell
        If .Cells(myrow, 10).Value <> "" And .Cells(myrow, 10).Value <> "NAME" Then ' <-- Ensure Column 'J' (10) is not empty and the item does not equal the word "NAME"
          If ListBox1.Value = .Cells(myrow, 2).Value Then ' <-- Set criteria to ensure Listbox 1 value is found in Column B
          NoDupes.Add .Cells(myrow, 10).Value, CStr(.Cells(myrow, 10).Value) ' <-- This removes any duplicate values
        If Err.Number = 0 Then
              ListBox2.AddItem Cells(myrow, 10).Value ' <-- This is what is actually populated to the listbox if the above scenarios are met.
              End If
              End If
              Err.Clear
              End If
        Next
    End With
    Sheets("NAVIGATOR").Activate
    Application.ScreenUpdating = True
    End Sub
    The above explained code is working 99.9% as expected.
    However, if i enter the exact same text in Column J(Column 10), but one in sentance case, and the other in CAPITALS, I do not have BOTH populated.

    Is there a line of code i can add to check the actual font capitalisation also to rectify this?

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Working with Listbox Duplicated values

    I thought the below also would have worked, but i then get no items:
    NoDupes.Add .Cells(myrow, 10).Value, CByte(.Cells(myrow, 10).Value) ' <-- Check the actual Bytes of the value

+ 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