Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default 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

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to paste only certain columns from a listbox into a named range

Thank you. I feel silly.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste to next empty cell in named range of cells Sully Excel Discussion (Misc queries) 3 March 4th 10 05:23 PM
Paste a named range to another range in Excel David Jean Excel Discussion (Misc queries) 2 April 13th 05 02:02 PM
Q: find range, listbox - format and fit columns Mark[_17_] Excel Programming 0 June 8th 04 12:41 PM
listbox not dsplaying all records in a named range Andy Excel Programming 4 April 30th 04 11:00 PM
Transfer multiple columns items form listbox to range Rolo[_3_] Excel Programming 3 November 15th 03 06:50 PM


All times are GMT +1. The time now is 11:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"