Results 1 to 6 of 6

Thread: [RESOLVED] Excel 2003 - Find cell value match in sheet Listbox

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    222

    Resolved [RESOLVED] Excel 2003 - Find cell value match in sheet Listbox

    First off, the code below is working for finding and selecting the value in a Listbox that matches the value in Cell A1. However I pieced this together through trial and error so I am not sure whether or not I did it in an unorthodox or sloppy manner.

    So my first question is my code ok?

    Second question is how difficult would it be to sort the items in the Listbox?
    -- if it requires API's at all then I'd prefer to skip it, but I was thinking it probably can be done in a straight forward manner.

    I've attached a sample workbook

    Thanks

    Frank

    Edit: I do realize that I should encase most of it between With and end with, I'll do that later

    Code:
    Option Explicit
    
    Private Sub CommandButton1_Click()
          Dim i As Integer
          
          For i = 1 To ListBox1.ListCount
              
              ListBox1.Selected(i - 1) = True
              
              If UCase(ListBox1.Value) = UCase(Range("A1").Value) Then
                  Exit For
              End If
    
          Next i
    End Sub
    
    Private Sub CommandButton2_Click()
    
    With Me.ListBox1
        .Clear
        .AddItem "pear"
        .AddItem "orange"
        .AddItem "three"
        .AddItem "GRAPE"
        .AddItem "Peach"
    End With
    
    End Sub
    Attached Files Attached Files
    Last edited by SQLADOman; Jan 21st, 2011 at 04:22 PM.

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