+ Reply to Thread
Results 1 to 4 of 4

Question using userforms with listboxes

  1. #1
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2019
    Posts
    87

    Question Question using userforms with listboxes

    I've noticed that not only do I need to select my choice from a listbox using the little arrows, if it is not already displayed in the listbox, I need to select it a second time (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?

    Can someone tell me how to detect the default value (or current value displayed) in the listbox without having to select it? Of if it MUST be selected, can I "select" that default value using VBA at the time I click the Add Entry button?

    Any assistance would be greatly appreciated. Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Question using userforms with listboxes

    Good morning imaquila

    Is this one question or two? I don't quite understand the first part of your question but maybe this will help.

    Add this line to the bottom of your Initialize routine to make the first item in the list the default. Just change the 0 to 1,2,3 etc to make subsequent items the default.
    Please Login or Register  to view this content.
    HTH

    DominicB

  3. #3
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 2019
    Posts
    87

    Re: Question using userforms with listboxes

    Thanks so much for your reply. I DO appreciate your time. My (limited) understanding of the use of: lstInvoice.Value = lstInvoice.List(0) is that it would always select the first value that was loaded into the listbox. Does selecting a different value from the list change that order? ie. a list box that lists values 1,2,3 and 3 is selected (being the visible value) would it now be list (0)? I may have misspoke when I used the term default. What I should have said is "the visible value in the listbox".

    Right now if I load values 1, 2, 3 and I use the arrow to select 3, 3 IS the visible value but because it is still not highlighted (blue), my code sees the list box value as NULL. Same is true if I want to leave the selection at 1 which is by default the visible value. If that IS the option I want, I have to still click on it to highlight it before it is NOT seen as a null value. My ONE question is " Is there a way in VBA to highlight the visible value when I click my "Add Entry" button eliminating that extra click to highlight that visible value?

    Thanks again for your time and BRAIN POWER!

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Question using userforms with listboxes

    Hi imaquila
    Quote Originally Posted by imaquila View Post
    Is there a way in VBA to highlight the visible value when I click my "Add Entry" button eliminating that extra click to highlight that visible value?
    I don't think so. The reason I'm not 100% sure is that the purpose of a listbox is to show a list that a user picks one or more items from a selection that are all visible. You are using a listbox that is only one character in height, so only one option is ever visible and that's not quite how the list box was designed to be used.

    If this is what you want you may want to consider using a combobox instead, with its dropdown which can be set to have a default value which would mean you wouldn't have to click on it at all?

    HTH

    DominicB

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Another Calendar Control question on Sheets and UserForms 2007
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2014, 08:27 AM
  2. UserForms & ListBoxes
    By JezLisle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2009, 11:49 AM
  3. Question about sizing Userforms programmatically
    By 39N 95W in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2006, 06:25 PM
  4. Userforms + Listboxes
    By sknudson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-27-2006, 12:03 PM
  5. Userforms Question
    By Jeff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2005, 01:05 PM

Tags for this Thread

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