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 array/subsript range error


Hi !

I've created a userform with different listboxes on it (total items in
the boxes 40). I managed to read out the multiple selections in the
boxes but for some reason it only works up to 5 or 6 items. I keep on
getting the following error message: "Run time error 9, Subscript out
of range" I've tried the suggestions in VBA Help but i do not get it
working. can anyone help?

this is the code I use:
---------------------------------------------------------------------------------
Private Sub CmdOK_Click()

With FrmZoneSheet.EU1list

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myarr1() As String
ReDim myarr1(EU1list.ListCount - 1)
tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt
For i = 0 To EU1list.ListCount - 1
If EU1list.Selected(i) = True Then
myarr1(j) = EU1list.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr1(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr1(j)
End With

With FrmZoneSheet.EU2list

Dim myarr2() As String
ReDim myarr2(EU2list.ListCount - 1)
tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To EU2list.ListCount - 1
If EU2list.Selected(i) = True Then
myarr2(j) = EU2list.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr2(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr2(j)
End With

With FrmZoneSheet.NAlist

Dim myarr3() As String
ReDim myarr3(NAlist.ListCount - 1)

tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To NAlist.ListCount - 1
If NAlist.Selected(i) = True Then
myarr3(j) = NAlist.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr3(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr3(j)
End With

With FrmZoneSheet.LAlist

Dim myarr4() As String
ReDim myarr4(LAlist.ListCount - 1)

tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To LAlist.ListCount - 1
If LAlist.Selected(i) = True Then
myarr4(j) = LAlist.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr4(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr4(j)
End With

With FrmZoneSheet.As1list

Dim myarr5() As String
ReDim myarr5(As1list.ListCount - 1)

tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To As1list.ListCount - 1
If As1list.Selected(i) = True Then
myarr5(j) = As1list.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr5(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr5(j)
End With

With FrmZoneSheet.As2list

Dim myarr6() As String
ReDim myarr6(As2list.ListCount - 1)

tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To As2list.ListCount - 1
If As2list.Selected(i) = True Then
myarr6(j) = As2list.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr6(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr6(j)
End With

With FrmZoneSheet.Palist

Dim myarr7() As String
ReDim myarr7(Palist.ListCount - 1)
tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To Palist.ListCount - 1
If Palist.Selected(i) = True Then
myarr7(j) = Palist.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr7(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr7(j)
End With

With FrmZoneSheet.MElist

Dim myarr8() As String
ReDim myarr8(MElist.ListCount - 1)

tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
k = lrt + 1
For i = 0 To MElist.ListCount - 1
If MElist.Selected(i) = True Then
myarr8(j) = MElist.List(i)
UnprotectSheet
ActiveSheet.Cells((k), fct) = myarr8(j)
j = j + 1
k = k + 1
End If
Next i
ReDim Preserve myarr8(j)
End With

If ChkROW.Value = True Then
tablename = "ZONE-TABLE"
DimensionsofTable tablename, frt, fct, lrt, lct
Cells(lrt + 1, fct).Value = "Rest of World"
End If


Unload Me
End Sub
---------------------------------------------------------------------------------

Thanks!


------------------------------------------------
~~ 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: 1
Default Userform array/subsript range error


Ok sorry to bother you all, I've resolved the problem by making the
array maximum elements equal to the total items of the listboxes
together

cheers,
mb


------------------------------------------------
~~ 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
Userform Error Steve B Excel Discussion (Misc queries) 2 February 6th 07 04:26 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
error in userform damorrison Excel Discussion (Misc queries) 6 April 23rd 06 03:18 PM
Changing a range of an array in a SUMPRODUCT formula gives a #N/A error Chrism Excel Discussion (Misc queries) 4 May 4th 05 04:06 PM


All times are GMT +1. The time now is 05:08 PM.

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"