+ Reply to Thread
Results 1 to 9 of 9

listbox items transfer

Hybrid View

  1. #1
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: listbox items transfer

    You can extent the OK button with
    Private Sub OKButton_Click()
       
        Dim LBCounter As Long
        
        For LBCounter = 0 To ListBox2.ListCount - 1
          Worksheets("List1").Cells(LBCounter + 1, "B") = ListBox2.List(LBCounter)
        Next
        
        Unload Me
        
    End Sub
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: listbox items transfer

    alternative

    Private Sub OKButton_Click()
           
        Worksheets("List1").Cells(1, 2).Resize(ListBox2.ListCount, 1) = ListBox2.List
        
        Unload Me
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-01-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: listbox items transfer

    It works, but if there are no items selected, then Run time error 1004 apears when I click ok button.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: listbox items transfer

    then add a line to check the listcount property first.

    Better yet only enable the button when listbox contains items.

  5. #5
    Registered User
    Join Date
    07-01-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: listbox items transfer

    I tried several codes but no one works. Errror always appears.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: listbox items transfer

    It would have helped if you had posted what you had tried and details on the error.

    Private Sub OKButton_Click()
    
        if listbox2.listcount>0 then   
           Worksheets("List1").Cells(1, 2).Resize(ListBox2.ListCount, 1) = ListBox2.List
        endif 
        Unload Me
    End Sub

  7. #7
    Registered User
    Join Date
    07-01-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: listbox items transfer

    And if ListBox2 is Multiselect and if I want to transfer only selected items (at once, not one by one) to worksheet (Columns B:B), how can I do 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