Question using forms with listboxes

jacatsos

New Member
Joined
Apr 5, 2013
Messages
5
I've noticed that not only do I need to select my choice from the listbox, I need to select it again (to get the blue highlight) before my selection is detected. Is there a way to use VBA to add the highlight once a selection from the listbox has been made or is it possible that I'm just checking for the wrong listbox property to read my selection and THAT'S why I have to select it a second time to highlight it before it's read by the VBA code?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You shouldn't need to select an item twice for it to be highlighted?

How have you populated the listbox?

What code do you have for it and the rest of the userform?
 
Upvote 0
Below is a simplified example of my user form with a list box. I've populated the list box with the most recent invoice number and the two following invoice numbers. If the new item is on the same (most recent invoice) which is already the value displayed in the listbox, there's no need to click on it except to highlight it. If I click the following invoices the numbers (to start a new invoice) they will be displayed in the listbox but their values remain NULL unless I click on them a second time. This leads me to believe that I should be using a different property to read the listbox selection. I've tried "Selection" and "Text" without success. I'm hoping that you might enlighten me to what I'm obviously missing. Thanks!

Code:
Private Sub cmdAdd_Click()
   Dim NewSalesWks As Worksheet
   
If IsNull(FrmInput.lstInvoice.Value) Then
         invoiceNbr = InputBox("Please enter the Invoice Number.")
        lstInvoice.Value = invoiceNbr
 Else: MsgBox ("Invoice " & lstInvoice.Value & " has been selected.")
End If
Set NewSalesWks = Worksheets("TotalSales")   'Add to Sales Sheet
        With NewSalesWks
        .Range("A2").Value = "4/15/14"
        .Range("B2").Value = FrmInput.lstInvoice.Value
    End With
End Sub


Private Sub UserForm_Initialize()
lstInvoice.Clear
lstInvoice.AddItem Sheets("TotalSales").Range("B2").Value   '(find last invoice number entered)
lstInvoice.AddItem Sheets("TotalSales").Range("B2").Value + 1 ' (add one to last invoice number entered)
lstInvoice.AddItem Sheets("TotalSales").Range("B2").Value + 2  ' (add two to last invoice number entered)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top