+ Reply to Thread
Results 1 to 3 of 3

How to paste only certain columns from a listbox into a named range

  1. #1
    GH
    Guest

    How to paste only certain columns from a listbox into a named range

    I am struggling with how to paste only the last two columns of a three
    column listbox (Listbox1) into a named range ("DataRange") on a
    worksheet ("Sheet1"). The number of rows and columns are not dynamic.
    Listbox1 always has 3 columns with 18 rows and DataRange always has 2
    columns and 18 rows. I want to paste the contents of columns 2 and 3
    from ListBox1 into DataRange.
    A simple task but I cannot get the syntax correct.

    GH


  2. #2
    Dick Kusleika
    Guest

    Re: How to paste only certain columns from a listbox into a named range

    GH

    Try something like this

    Private Sub CommandButton1_Click()

    Dim rData As Range
    Dim i As Long, j As Long

    Set rData = Sheet1.Range("DataRange")

    For i = 0 To Me.ListBox1.ListCount - 1
    For j = 1 To 2 'columns start at zero, this is cols 2 and 3
    rData.Cells(i + 1, j).Value = Me.ListBox1.List(i, j)
    Next j
    Next i

    End Sub

    --
    **** Kusleika
    Excel MVP
    Daily Dose of Excel
    www.*****-blog.com

    GH wrote:
    > I am struggling with how to paste only the last two columns of a three
    > column listbox (Listbox1) into a named range ("DataRange") on a
    > worksheet ("Sheet1"). The number of rows and columns are not dynamic.
    > Listbox1 always has 3 columns with 18 rows and DataRange always has 2
    > columns and 18 rows. I want to paste the contents of columns 2 and 3
    > from ListBox1 into DataRange.
    > A simple task but I cannot get the syntax correct.
    >
    > GH




  3. #3
    GH
    Guest

    Re: How to paste only certain columns from a listbox into a named range

    Thank you. I feel silly.


+ 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