+ Reply to Thread
Results 1 to 5 of 5

Select UserForm ListBox Value For Closed WB Input

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Select UserForm ListBox Value For Closed WB Input

    Hi all,

    Seems my problems are never ending.

    Using a userforms listbox item. BTW only 1 item is listed. I'm trying to select that
    item with code so the value/text can be copied over to an previously closed workbook(WB). Currently, I'm trying to select the item using the following:

    Please Login or Register  to view this content.
    It seems that the method that I'm using to select the list box items doesn't always work.
    My MsgBox will return a empty box. Where if I walk through the code and manually select the listbox I will get LB5 to hold the listbox5 value.


    I've been trying to figure this out over the past few days. Any help as always much appreciated.

    Thanks,

    BDB
    Last edited by bdb1974; 04-19-2011 at 06:03 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Select UserForm ListBox Value For Closed WB Input

    It seems to me that you are not declaring your LB5 variable. You probably want to declare it as a string, then get the value from the listbox using the .Value property. As is, LB5 is not declared a certain data type, and when you set it to your listbox it probably is using the Object data type.

    Please Login or Register  to view this content.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Select UserForm ListBox Value For Closed WB Input

    davegugg, In my example i just forgot to show that I had dim'd LB5 As string.

    I know that's not my problem.

    In regards to setting
    LB5 = Me.ListBox5.Value

    I've tried this too.

    I've got 3 list boxes I'm trying to obtain info from. I've placed a msgbox after each
    string variable to visually show me what the value is for each LB. Running the following
    code will leave the first LB empty, the second LB will capture the listbox2 value and
    the 3rd LB will be empty.


    Please Login or Register  to view this content.

    Still seems the only way I can get all 3 listboxes values is to manually select them.

    I didn't want to do this but I might have better luck using textboxes.

    Still hoping someone might have a solution.

    thanks,

    BDB

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Select UserForm ListBox Value For Closed WB Input

    If a listbox contains an item (not empty) , then maybe do something like
    for each item in listbox add to an array then from the array set a variable
    equal to the element in the array?

    Goto be another way of pulling this value out of the listbox.


    BDB

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Select UserForm ListBox Value For Closed WB Input

    Great news! I stumbled accross an idea which actually works.

    Here's goes:

    Dim LB3 As string
    Dim lItem as Integer

    For lItem = 0 To ListBox3.ListCount - 1

    If ListBox3.Selected(lItem) = True Then
    LB3 = Me.ListBox3.List(lItem)
    LB3 = LB3
    MsgBox LB3
    ListBox3.Selected(lItem) = False
    End If

    Next

    I did this for all 3 listboxes and got all 3 to return with the item listed.

    Yeah!!!!

    Regards,

    BDB

+ 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