+ Reply to Thread
Results 1 to 5 of 5

Copy data from Listbox columns to Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-21-2009
    Location
    Rotterdam, The Netherlands
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Question Copy data from Listbox columns to Sheet

    Hi,

    I'd like to transfer columns 1, 2 and 4 from a userform listbox to columns A, B and C of a worksheet, but find this to be beyond my reach. Can anyone help me with a code that does this? Thanks a lot.
    Last edited by WCJanssen; 04-30-2011 at 08:06 AM. Reason: solved; changed prefix

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy data from Listbox columns to Sheet

    Hello WCJanssen,

    The macro below will copy the columns of the List Box to the worksheet starting at cell "A1". Change the list box name if you need to and the starting cell in column "A" as well.
    Sub CopyListData()
    
      Dim Data() As Variant
      Dim I As Long
      
        ReDim Data(ListBox1.ListCount - 1, 2)
        
          For I = 0 To UBound(Data)
            Data(I, 0) = ListBox1.List(I, 0)
            Data(I, 1) = ListBox1.List(I, 1)
            Data(I, 2) = ListBox1.List(I, 3)
          Next I
        
        Range("A1").Resize(I, 3) = Data
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Copy data from Listbox columns to Sheet

    Private Sub CommandButton1_Click()
       With ThisWorkbook.Sheets("Sheet1")
          For i = 0 To Me.ListBox1.ListCount - 1
             .Cells(i + 1, "A").Value = Me.ListBox1.Column(0, i)
             .Cells(i + 1, "B").Value = Me.ListBox1.Column(1, i)
             .Cells(i + 1, "C").Value = Me.ListBox1.Column(3, i)
          Next i
       End With
    End Sub

  4. #4
    Registered User
    Join Date
    06-21-2009
    Location
    Rotterdam, The Netherlands
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Re: Copy data from Listbox columns to Sheet

    thanks! that did the trick.

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

    Re: Copy data from Listbox columns to Sheet

    or
    sub snb()
      Sheets(1).Cells(1).Resize(ListBox1.ListCount, UBound(ListBox1.List, 2) + 1) = ListBox1.List
      Sheets(1).columns(3).delete
    End Sub



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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