PC Review


Reply
Thread Tools Rate Thread

code to parse a multi-colum multi-select listbox

 
 
Jade
Guest
Posts: n/a
 
      16th Sep 2008
Hello Everyone,

I need some help. I need to develop code to parse a multi-column
multi-select listbox and put the values in a worksheet.

This is the code I have but it's only giving me the last item selected
and I need to capture all items selected in the multi-select, multi-
column Listbox.

With Me.ListBox2
For i = 0 To .ListCount - 1
If .Selected(i) Then
UserForm1.Spreadsheet1.Range("a65536").End(xlUp) = sPrompt
& .Column(0, i)
UserForm1.Spreadsheet1.Range("B65536").End(xlUp) = sPrompt
& .Column(1, i)
End If
Next i

Again, any help would be great.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      16th Sep 2008
This worked ok for me:

Option Explicit
Private Sub CommandButton1_Click()
Dim sPrompt As String
Dim iCtr As Long
Dim cCtr As Long
Dim destcell As Range
Dim wks As Worksheet

sPrompt = "a-"
Set wks = Worksheets("sheet2")

With wks
Set destcell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

With Me.ListBox2
For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
For cCtr = 0 To .ColumnCount - 1
destcell.Offset(0, cCtr).Value = sPrompt & .List(iCtr, 0)
Next cCtr
Set destcell = destcell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range

Set myRng = Worksheets("sheet1").Range("a1:b3")
With Me.ListBox2
.ColumnCount = myRng.Columns.Count
.MultiSelect = fmMultiSelectMulti
.List = myRng.Value
End With
End Sub


Jade wrote:
>
> Hello Everyone,
>
> I need some help. I need to develop code to parse a multi-column
> multi-select listbox and put the values in a worksheet.
>
> This is the code I have but it's only giving me the last item selected
> and I need to capture all items selected in the multi-select, multi-
> column Listbox.
>
> With Me.ListBox2
> For i = 0 To .ListCount - 1
> If .Selected(i) Then
> UserForm1.Spreadsheet1.Range("a65536").End(xlUp) = sPrompt
> & .Column(0, i)
> UserForm1.Spreadsheet1.Range("B65536").End(xlUp) = sPrompt
> & .Column(1, i)
> End If
> Next i
>
> Again, any help would be great.


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-Select Listbox VBA code causing overflow in loop Mark Burk Microsoft Access 1 23rd Aug 2007 12:48 AM
Multi Select Listbox Code =?Utf-8?B?QWxleA==?= Microsoft Access Forms 3 13th Oct 2006 09:26 PM
How to reset a multi-select listBox via code? Alp Bekisoglu Microsoft Access 4 29th Jan 2006 10:31 AM
Multi Colum Listbox in UserForm =?Utf-8?B?WmFuaQ==?= Microsoft Excel Programming 2 13th Jan 2006 12:05 AM
multi colum listbox alexanderd Microsoft Excel Misc 9 3rd Jun 2004 08:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:17 AM.