+ Reply to Thread
Results 1 to 5 of 5

VBA - Userform; Check if at least one selection has been made in Listbox

  1. #1
    Forum Contributor
    Join Date
    05-16-2018
    Location
    Pittsburgh, PA
    MS-Off Ver
    2016
    Posts
    109

    VBA - Userform; Check if at least one selection has been made in Listbox

    Hello everyone,

    Wondering if I could have some help with a small problem in my userform to add data to a sheet?

    To do so, I made an userform that gives you four fields to fill/select. Text box: New restriction name, Text box: Row # to add line, Listbox: Select Board category, Listbox: Select financial manager

    With the code I have now, it is successful in bringing over the data. However, when checking the userform to insert data, I noticed that if you did not select any options for the any of the listboxes than it still would enter the text box data and leave the other fields blank and not ask that no selection has been made and thus requiring to do so like if you left a text box empty.

    For simplicity: The code (in insert data button in userform) for the checks work for the text boxes but not the listboxes. Thought I could find a quick solution but have not been able to, I would think this would be quite simple but need some help if anyone knows a way.

    Please Login or Register  to view this content.
    Thanks,
    Ant
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: VBA - Userform; Check if at least one selection has been made in Listbox

    If nothing has been selected in a simple UserForm's ListBox, then that ListBox's ListIndex will be -1. For example...

    Please Login or Register  to view this content.

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA - Userform; Check if at least one selection has been made in Listbox

    utilise
    Please Login or Register  to view this content.
    Edit - Already answered by Rick above
    Last edited by nigelog; 10-15-2019 at 11:15 AM.

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: VBA - Userform; Check if at least one selection has been made in Listbox

    Quote Originally Posted by nigelog View Post
    utilise
    Please Login or Register  to view this content.
    Edit - Already answered by Rick above
    You have a typo in your suggested code... you accidentally wrote .ListCount instead of .ListIndex

    EDIT NOTE: nigelog has corrected the typo which I was pointing out above.
    Last edited by Rick Rothstein; 10-15-2019 at 11:50 AM.

  5. #5
    Forum Contributor
    Join Date
    05-16-2018
    Location
    Pittsburgh, PA
    MS-Off Ver
    2016
    Posts
    109

    Re: VBA - Userform; Check if at least one selection has been made in Listbox

    Awesome, it works perfectly!

    Here is the code that was adjusted...

    Please Login or Register  to view this content.
    Thanks for the help @Rick Rothstein and @nigelog

    Thanks,
    Ant

+ 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. Check ListBox selection made
    By AndyE in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2018, 11:05 AM
  2. [SOLVED] How to ensure that a ListBox selection is made
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-04-2017, 12:00 PM
  3. [SOLVED] Listbox selection bug (selection is automatically made when it shouldn't be)
    By seleseped in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2017, 01:06 PM
  4. Creating a Range of a Listbox based on the Selection Made in Another ListBox
    By masood78 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-02-2014, 11:03 AM
  5. How do I get my Listbox to return the selection made?
    By imaquila in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 02-14-2012, 06:21 PM
  6. Replies: 0
    Last Post: 11-30-2005, 12:50 PM
  7. how to check if user has made a selection on the sheet
    By chawla12amit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2005, 03:51 PM

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