Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Userform and reading multiple listboxes


Hi all,

I've got a userform with 8 different listboxes. All items in the
different listboxes are loaded by an userform_initialize sub.
Under the ok button I want to have a piece of code that put's all
selected items in a list on a sheet. The listboxes multiselection
property is true

for reading out a multiselection list box I use:
---------------------------------------------------------------------------------
Public Function FillArray() As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myarr() As String
ReDim myarr(ListBox1.ListCount - 1)
k = 1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
myarr(j) = ListBox1.List(i)
Sheets("Zone Table format").Cells((k), "A") = myarr(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr(j)
FillArray = myarr(j)
End Function
-----------------------------------------------------------------------------

This works with a normal list box in Excel. However I do not seem to
get it working in combination with a userform. I keep on getting back
the error message: "no object", so Excel seems not to recognize the 8
list boxes.

I've initialized my userform in the following manner (shows only a
part):
---------------------------------------------------------------------------------
Private Sub UserForm_Initialize()

With EU1list
..AddItem "Europe 1"
..AddItem "Belgium"
..AddItem "France North"
..AddItem "France Rest"
..AddItem "Germany"
..AddItem "Italy"
..AddItem "Luxembourg"
..AddItem "Netherlands"
..AddItem "United Kingdom"
..MultiSelect = fmMultiSelectExtended
End With


With NAlist
..AddItem "North America"
..AddItem "Canada"
..AddItem "United States"
..MultiSelect = fmMultiSelectExtended
End With

With LAlist
..AddItem "Latin America"
..AddItem "Argentina"
..AddItem "Brazil"
..AddItem "Chile"
..AddItem "Mexico"
..MultiSelect = fmMultiSelectExtended
End With

'etc etc

End With

End sub
----------------------------------------------------------------------------------


Does any one know how I can let the listboxes to be recognised by VBA?
So what should I put in the privat sub of the CmdOK button to get my
selected items in one single column?

I really hope someone can solve this
Many thanks in advance

cheers
maarten


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Userform and reading multiple listboxes

Hi Bijl167,

Does any one know how I can let the listboxes to be recognised by VBA?


Precede them with the userform's name:

With Userform1.Lisbox1
...
End With

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Userform and reading multiple listboxes

Maarten,

Have you tried preceding the reference to the listboxes by the userform name
, for example

If Userform1.ListBox1.Selected(i) = True Then

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bijl167" wrote in message
...

Hi all,

I've got a userform with 8 different listboxes. All items in the
different listboxes are loaded by an userform_initialize sub.
Under the ok button I want to have a piece of code that put's all
selected items in a list on a sheet. The listboxes multiselection
property is true

for reading out a multiselection list box I use:
--------------------------------------------------------------------------

-------
Public Function FillArray() As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myarr() As String
ReDim myarr(ListBox1.ListCount - 1)
k = 1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
myarr(j) = ListBox1.List(i)
Sheets("Zone Table format").Cells((k), "A") = myarr(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr(j)
FillArray = myarr(j)
End Function
--------------------------------------------------------------------------

---

This works with a normal list box in Excel. However I do not seem to
get it working in combination with a userform. I keep on getting back
the error message: "no object", so Excel seems not to recognize the 8
list boxes.

I've initialized my userform in the following manner (shows only a
part):
--------------------------------------------------------------------------

-------
Private Sub UserForm_Initialize()

With EU1list
AddItem "Europe 1"
AddItem "Belgium"
AddItem "France North"
AddItem "France Rest"
AddItem "Germany"
AddItem "Italy"
AddItem "Luxembourg"
AddItem "Netherlands"
AddItem "United Kingdom"
MultiSelect = fmMultiSelectExtended
End With


With NAlist
AddItem "North America"
AddItem "Canada"
AddItem "United States"
MultiSelect = fmMultiSelectExtended
End With

With LAlist
AddItem "Latin America"
AddItem "Argentina"
AddItem "Brazil"
AddItem "Chile"
AddItem "Mexico"
MultiSelect = fmMultiSelectExtended
End With

'etc etc

End With

End sub
--------------------------------------------------------------------------

--------


Does any one know how I can let the listboxes to be recognised by VBA?
So what should I put in the privat sub of the CmdOK button to get my
selected items in one single column?

I really hope someone can solve this
Many thanks in advance

cheers
maarten


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Userform and reading multiple listboxes


I've tried:

Private Sub CmdOK_Click()
With FrmZoneSheet.EU1list
FillArray
End With

Unload Me
End Sub

this does not work. The error message still shows "Object required"

I've also tried:

Private Sub CmdOK_Click()

With FrmZoneSheet.EU1list

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myarr() As String
ReDim myarr(FrmZoneSheet.Eulist.ListCount - 1)
k = 1

For i = 0 To FrmZoneSheet.Eulist.ListCount - 1

If FrmZoneSheet.Eulist.Selected(i) = True Then

myarr(j) = FrmZoneSheet.Eulist.List(i)
Sheets("Zone Table format").Cells((k), "A") = myarr(j)
j = j + 1
k = k + 1

End If
Next i
ReDim Preserve myarr(j)
End With

Unload Me
End Sub

his generates the error message: "method or data member not found


Any other suggestions

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
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
Reading Multiple Files BadBoy Excel Worksheet Functions 5 January 15th 10 06:26 PM
Is there a way to create multiple listboxes in same collumn? Ken C[_2_] Excel Discussion (Misc queries) 0 September 25th 09 07:50 PM
Multiple listboxes to update pivot table? Cam Excel Discussion (Misc queries) 1 May 18th 09 04:55 PM
Reading fields from multiple new files marko Excel Discussion (Misc queries) 0 May 12th 08 05:21 AM
Userform reading a cell value Ron de Bruin Excel Programming 0 August 8th 03 12:55 PM


All times are GMT +1. The time now is 10:46 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"