Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Extract values from a multi-select multi-column list-box

I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors' to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a NUL
string (""). Can't seem to be able to assign the value in the 2nd column.

Any help or suggestions or ideas or better ways of doing this would be most
welcolm.

Thanks in advance,
Peter Bircher




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extract values from a multi-select multi-column list-box

Private Sub cmdRun_Click()
Dim i As Integer, j as Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
j = 0
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(j) = LBoxContractors.List(i,0)
VatRegistration(j) = LBoxContractors.List(i,1)
j = j + 1
End If
Next i
End If
End sub

--
Regards,
Tom Ogilvy


Peter wrote in message
...
I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors' to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of

the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string

arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a NUL
string (""). Can't seem to be able to assign the value in the 2nd column.

Any help or suggestions or ideas or better ways of doing this would be

most
welcolm.

Thanks in advance,
Peter Bircher






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Extract values from a multi-select multi-column list-box

Tom, you are a star!

Once again, my sincerest thanks,
Peter


Tom Ogilvy wrote in message
...
Private Sub cmdRun_Click()
Dim i As Integer, j as Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
j = 0
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(j) = LBoxContractors.List(i,0)
VatRegistration(j) = LBoxContractors.List(i,1)
j = j + 1
End If
Next i
End If
End sub

--
Regards,
Tom Ogilvy


Peter wrote in message
...
I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors'

to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of

the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string

arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a

NUL
string (""). Can't seem to be able to assign the value in the 2nd

column.

Any help or suggestions or ideas or better ways of doing this would be

most
welcolm.

Thanks in advance,
Peter Bircher








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Extract values from a multi-select multi-column list-box

When you use multi-select, then the listbox's .text property is empty. It won't
contain all the values you have selected. And watch out for the .listIndex
stuff with multiselect turned on. It just returns the row that has
focus--doesn't matter if that row was selected or not.

But you could get it this kind of way:

Option Explicit

Private Sub cmdRun_Click()

Dim i As Long
Dim Contractor() As String
Dim VatRegistration() As String

ReDim Contractor(0 To Me.LBoxContractors.ListCount - 1)
ReDim VatRegistration(0 To Me.LBoxContractors.ListCount - 1)

For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i, 0)
VatRegistration(i) = LBoxContractors.List(i, 1)
End If
Next i

End Sub

Private Sub UserForm_Initialize()

With Me.LBoxContractors
.List = Worksheets("sheet1").Range("a1:b5").Value
.MultiSelect = fmMultiSelectMulti
.BoundColumn = 1
'.TextColumn = 2
End With

End Sub

You'll end up with an array with the same number of elements as the the
listbox. Some elements may be blank if not checked.

Another way to just get an array of the selected items:
Option Explicit

Private Sub cmdRun_Click()
Dim Contractor() As String
Dim VatRegistration() As String
Dim i As Long
Dim selCtr As Long

selCtr = -1
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
selCtr = selCtr + 1
ReDim Preserve Contractor(0 To selCtr)
ReDim Preserve VatRegistration(0 To selCtr)
Contractor(selCtr) = LBoxContractors.List(i, 0)
VatRegistration(selCtr) = LBoxContractors.List(i, 1)
End If
Next i

If selCtr = -1 Then
MsgBox "nothing selected"
End If

End Sub

Then later on you could loop through that (probably) smaller array.




Peter wrote:

I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors' to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a NUL
string (""). Can't seem to be able to assign the value in the 2nd column.

Any help or suggestions or ideas or better ways of doing this would be most
welcolm.

Thanks in advance,
Peter Bircher


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Extract values from a multi-select multi-column list-box

Hi Dave

Thanks for your detailed response.
I have implemented Tom's suggestion (has similar components) and it seems to
do the job very well. What I get is and array of only the selected items
which is very neat (as your second solutuion shows) - looks great - I think
I will will also give it a try - one learns *so much* from this newsgroup.

In you solution, is this correct?
'.TextColumn = 2
Should it be remmed out ?

I think I will bring in the redimentioned array variables as suggested -
saving some RAM!

Peter

Dave Peterson wrote in message
...
When you use multi-select, then the listbox's .text property is empty. It

won't
contain all the values you have selected. And watch out for the

..listIndex
stuff with multiselect turned on. It just returns the row that has
focus--doesn't matter if that row was selected or not.

But you could get it this kind of way:

Option Explicit

Private Sub cmdRun_Click()

Dim i As Long
Dim Contractor() As String
Dim VatRegistration() As String

ReDim Contractor(0 To Me.LBoxContractors.ListCount - 1)
ReDim VatRegistration(0 To Me.LBoxContractors.ListCount - 1)

For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i, 0)
VatRegistration(i) = LBoxContractors.List(i, 1)
End If
Next i

End Sub

Private Sub UserForm_Initialize()

With Me.LBoxContractors
.List = Worksheets("sheet1").Range("a1:b5").Value
.MultiSelect = fmMultiSelectMulti
.BoundColumn = 1
'.TextColumn = 2
End With

End Sub

You'll end up with an array with the same number of elements as the the
listbox. Some elements may be blank if not checked.

Another way to just get an array of the selected items:
Option Explicit

Private Sub cmdRun_Click()
Dim Contractor() As String
Dim VatRegistration() As String
Dim i As Long
Dim selCtr As Long

selCtr = -1
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
selCtr = selCtr + 1
ReDim Preserve Contractor(0 To selCtr)
ReDim Preserve VatRegistration(0 To selCtr)
Contractor(selCtr) = LBoxContractors.List(i, 0)
VatRegistration(selCtr) = LBoxContractors.List(i, 1)
End If
Next i

If selCtr = -1 Then
MsgBox "nothing selected"
End If

End Sub

Then later on you could loop through that (probably) smaller array.




Peter wrote:

I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors'

to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of

the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string

arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a

NUL
string (""). Can't seem to be able to assign the value in the 2nd

column.

Any help or suggestions or ideas or better ways of doing this would be

most
welcolm.

Thanks in advance,
Peter Bircher


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Extract values from a multi-select multi-column list-box

If you toggle the multiselect off, then it'll be useful. But what did it always
return when you had multiselect turned on? Blanks. That's why I didn't figure
you needed it.





Peter wrote:

Hi Dave

Thanks for your detailed response.
I have implemented Tom's suggestion (has similar components) and it seems to
do the job very well. What I get is and array of only the selected items
which is very neat (as your second solutuion shows) - looks great - I think
I will will also give it a try - one learns *so much* from this newsgroup.

In you solution, is this correct?
'.TextColumn = 2
Should it be remmed out ?

I think I will bring in the redimentioned array variables as suggested -
saving some RAM!

Peter

Dave Peterson wrote in message
...
When you use multi-select, then the listbox's .text property is empty. It

won't
contain all the values you have selected. And watch out for the

.listIndex
stuff with multiselect turned on. It just returns the row that has
focus--doesn't matter if that row was selected or not.

But you could get it this kind of way:

Option Explicit

Private Sub cmdRun_Click()

Dim i As Long
Dim Contractor() As String
Dim VatRegistration() As String

ReDim Contractor(0 To Me.LBoxContractors.ListCount - 1)
ReDim VatRegistration(0 To Me.LBoxContractors.ListCount - 1)

For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i, 0)
VatRegistration(i) = LBoxContractors.List(i, 1)
End If
Next i

End Sub

Private Sub UserForm_Initialize()

With Me.LBoxContractors
.List = Worksheets("sheet1").Range("a1:b5").Value
.MultiSelect = fmMultiSelectMulti
.BoundColumn = 1
'.TextColumn = 2
End With

End Sub

You'll end up with an array with the same number of elements as the the
listbox. Some elements may be blank if not checked.

Another way to just get an array of the selected items:
Option Explicit

Private Sub cmdRun_Click()
Dim Contractor() As String
Dim VatRegistration() As String
Dim i As Long
Dim selCtr As Long

selCtr = -1
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
selCtr = selCtr + 1
ReDim Preserve Contractor(0 To selCtr)
ReDim Preserve VatRegistration(0 To selCtr)
Contractor(selCtr) = LBoxContractors.List(i, 0)
VatRegistration(selCtr) = LBoxContractors.List(i, 1)
End If
Next i

If selCtr = -1 Then
MsgBox "nothing selected"
End If

End Sub

Then later on you could loop through that (probably) smaller array.




Peter wrote:

I have a multi-select list box with the column count property set to 2
The program (before loading the form) sets the range name 'Contractors'

to
cover two columns: The contractors' names and their respective VAT
registration numbers.

The form loads Rowsource with Factors!Contractors and shows the names of

the
contractors and their VAT registration numbers. So far so good.
The user is asked to select one (or more) contractors.

I am trying to get the routine below to load the two (Public) string

arrays:
Contractor(xx) and VatRegistration(xx) with the values wherever a
selection(s) is made:

Extract from the 'Run' button code:

Private Sub cmdRun_Click()
Dim i As Integer
LBoxContractors.BoundColumn = 1
LBoxContractors.TextColumn = 2
If LBoxContractors.ListIndex < -1 Then
For i = 0 To LBoxContractors.ListCount - 1
If LBoxContractors.Selected(i) Then
Contractor(i) = LBoxContractors.List(i)
VatRegistration(i) = LBoxContractors.Text
End If
Next i
End If
End sub

The Contractor(i) loads up fine but the VatRegistration(i) has just a

NUL
string (""). Can't seem to be able to assign the value in the 2nd

column.

Any help or suggestions or ideas or better ways of doing this would be

most
welcolm.

Thanks in advance,
Peter Bircher


--

Dave Peterson


--

Dave Peterson

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
How to find a value with multi-column, multi-record list Dallasm Excel Worksheet Functions 1 May 30th 10 05:40 PM
Multi Select from Drop List PatriciaT Excel Discussion (Misc queries) 2 September 8th 09 06:33 PM
how do I select multi values from a list Tommy Excel Discussion (Misc queries) 1 July 12th 06 09:38 AM
List Box Multi Select Option ann_nyc Excel Worksheet Functions 0 October 11th 05 05:56 PM
Multi Select List Box jacqui Excel Programming 0 July 22nd 03 12:12 PM


All times are GMT +1. The time now is 07:38 AM.

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

About Us

"It's about Microsoft Excel"