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





Reply With Quote