![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
I've created a form with a multiselect listbox to allow people to choose which quarterly file(s) they would like to open and have summarised. I wanted to read the items selected into an array, then pass this to an 'opening' procedure prior to getting the data out from the spreadsheet(s). The problem I have is with the code below (run when the form's command button is clicked), which I just put in to make sure that it was picking up the selected items correctly. Using the locals windows shows that the selected items are being read in ocrrectly, however this then stalls with a subscript out of range error on the second for... next routine. Any ideas on what I'm doing wrong?
Option Explicit Dim x As Integer Public Sub Main() Dim y As Integer Dim myarray() For x = 0 To frmMain.lstQtr.ListCount - 1 If frmMain.lstQtr.Selected(x) Then ReDim Preserve myarray(y) myarray(y) = frmMain.lstQtr.List(x) y = y + 1 End If Next x For y = 0 To UBound(myarray(y)) MsgBox myarray(y) Next y End Sub |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Solved it, sorry, it should be UBound(myarray) not UBound(myarray(y)). Dopey sod, me
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|