+ Reply to Thread
Results 1 to 21 of 21

Listbox to String

  1. #1
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Listbox to String

    Hi all

    I have a Userform with a listbox called listbox2
    I want the entire contents of this list box to be in a string in Variable Recs

    I have this
    Please Login or Register  to view this content.
    And it works
    but I believe there is an easier way to do it
    I think using the list properity
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Listbox to String

    Please Login or Register  to view this content.



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

    Re: Listbox to String

    I don't think that you can avoid the loop, how is the listbox populated?
    Hope that helps.

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

    Free DataBaseForm example

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    If you populated using List or Rowsource (assuming a one column range) then you'll need to transpose before you join; if you used additem, then you need to loop.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Listbox to String

    Please Login or Register  to view this content.
    Last edited by snb; 07-07-2011 at 05:29 AM.

  6. #6
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    Please Login or Register  to view this content.
    which method is that?

    How do you transpose?

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    Nicely contrived.
    Now try this:
    Please Login or Register  to view this content.
    Last edited by romperstomper; 07-07-2011 at 05:01 AM.

  8. #8
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    ok having a play with that.

    got my head round the examples. i think.
    so transpose only works when the listbox is populated in one of the above ways?

    so will i be stuck with the loop?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    Since you haven't told us how you are populating it, we can't really say.

  10. #10
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    [QUOTE=FRIEL;2558478]
    Please Login or Register  to view this content.
    QUOTE]

    sorry this is in the Initialize event on the form

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    Then you need to use Join and application.Transpose as shown.

  12. #12
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    =/

    any reason this wont work?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    Depends - how is Listbox2 being populated?

  14. #14
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    =S

    ok lil wired
    the above works now
    it wouldnt work before.

    thanks guys

    I'd add Rep
    but i added Rep to you last time and it wont let me add to you again lol

  15. #15
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    =S Now it dosent!

    this is kinda frustrating.....

    Populated by
    Please Login or Register  to view this content.
    in the Initialize event

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    You refer to Listbox1 in one code and Listbox2 in the other - which is it? Also, it helps if you tell us what error you are getting: we always want more information than "it doesn't work"

    I don't really care about the rep, though I thank you for the thought.

  17. #17
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    Please Login or Register  to view this content.
    like this
    what an idiot.
    i totaly missed that

    Run-time error '13':
    Type Mismatch

    sorry for the confusion

  18. #18
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    Since you are populating Listbox2 with additem, you'll have to loop.

  19. #19
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Re: Listbox to String

    ok
    thanks for your help

    at least i have learned somthing =D

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Listbox to String

    Please Login or Register  to view this content.

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Listbox to String

    I assume you don't expect a response to that?

+ 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