+ Reply to Thread
Results 1 to 7 of 7

Look at values in listbox not the number of items

  1. #1
    Registered User
    Join Date
    05-04-2009
    Location
    San Diego, California
    MS-Off Ver
    Excel 2003
    Posts
    43

    Look at values in listbox not the number of items

    When the code below is placed behind a command button, if ListBox1 has 1 item in it a message box will appear. However if ListBox1 has 2 or more items in it another macro will run. I want to alter the code so it will check whether the value in ListBox1 is equal to 1.If the value is equal to 1 then I’d like to display the message box. If the value is greater than 1, I would like to call the alternative code. The code I am using looks at the number of items in the ListBox not the value. I am not sure how to get the code to look at the value. Thank you in advance.

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look at values in listbox not the number of items

    Hi,
    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor Sadath31's Avatar
    Join Date
    03-02-2011
    Location
    Dammam, Saudi Arabia
    MS-Off Ver
    Office 365
    Posts
    452

    Re: Look at values in listbox not the number of items

    Please Login or Register  to view this content.

    should select one item in the listbox

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look at values in listbox not the number of items

    Hi,

    I don't know what you mean. You asked what the value of list box 1 was. That's what the syntax I gave you does.

    Regards

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Look at values in listbox not the number of items

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    05-04-2009
    Location
    San Diego, California
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Look at values in listbox not the number of items

    I am sorry for not being clearer Richard. I am trying to sum the numbers in the ListBox. If the total sum is 1 then I want to display a message box. However if the total sum is greater than 1 then I want to call Macro 2. Can you help me?
    Last edited by Buddy7; 05-17-2011 at 09:07 PM.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Look at values in listbox not the number of items

    Hi,

    OK I'm guessing that your UserForm list box contains numbers in the first column, the BoundColumn property is set to 1 and the MultiSelect property is set to Multi so that you can pick various items from it. That wasn't obvious from your post.

    In which case call the following procedure from a Command Button on your UserForm

    Please Login or Register  to view this content.
    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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