+ Reply to Thread
Results 1 to 7 of 7

Userform Listbox Value

  1. #1
    Registered User
    Join Date
    04-07-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    8

    Userform Listbox Value

    I am having trouble with retrieving the value of the selected item in the listbox. Each value in the listbox is the name of a city. Each city has a corresponding hidden worksheet that bears the name of the city. I have a button on the userform that when pressed unhides and selects the correct cities worksheet (correct meaning it is the city that is selected in the listbox.) .Right now I have this code to find the value, but I am having trouble with it. Thanks for any help!


    Private Sub cmdViewData_Click()
    Dim i As Integer

    For i = 0 To LBCities.ListCount - 1
    Next i
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,359

    Re: Userform Listbox Value

    Hi IBahamut

    Example 6 on this site shows how to use the index number and "true" if selected..

    http://www.globaliconnect.com/excel/...=79&Itemid=475

    If that doesn't help then attach your workbook so we can play with the code and make it work.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-07-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    8

    Re: Userform Listbox Value

    Here is my file. After fiddling around I was able to set a variable and find out the value that way. What I am trying to do is that when I click the View Sales Data button on the userform, I need to go to the sheet with the same name and display a message box saying the total sales for that city. My code is a bit messy, I'm still learning quite a bit. Thanks!
    Attached Files Attached Files
    Last edited by IBahamut; 04-13-2015 at 09:19 PM.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,359

    Re: Userform Listbox Value

    Hi,

    This looks like the problem we all go through. It called "What the F is the name of that object"? I normally go to the immediate window and do a debug.print followed by something like userform1.listbox.count and press enter. I normally get an error message until I can figure out what name the object is. "Me" is the object you are in so you might need to add it in front of yoyur LBCities listbox. I did a little tweeking and see the below. I gave up as I didn't find all those hidden sheets in your example. BUT the below seemed to work.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-07-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    8

    Re: Userform Listbox Value

    When I run this code, I am getting a "compile error : method or data member not found" and it highlights the section " If Me.LBCities.Selected(i)" Do you know what might be causing this?

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,359

    Re: Userform Listbox Value

    I think from that site above you need to put a true in there, like

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-07-2015
    Location
    Illinois
    MS-Off Ver
    2013
    Posts
    8

    Re: Userform Listbox Value

    Got it! Thanks for all your help!

+ 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. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  2. [SOLVED] copy contents of userform listbox to another userform listbox
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2014, 11:39 AM
  3. Transfer Data From One Userform Listbox to Another Userform Listbox with 11 columns
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2013, 10:54 AM
  4. userform listbox
    By tsiguy96 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-14-2013, 11:09 PM
  5. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 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