Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Fill Array from Selected Items in Text Box

I'm working this out by trial and error and could use some help. I've
got a UserForm with a ListBox called lbProcess. It's RowSource
property is a two column range in a worksheet. If I select two or more
items, it seems to work ok. If I only select one item, I get a
"Subscript Out of Range" error and debug highlights the line marked
below. I assume that I'm not declaring the array correctly. Any
guidance would be appreciated.

Private Sub cmdProcessesPicked_Click()
cnt = 0

'''''''''''''''''''''''''''''''''''''''''determine number of selected
items
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then cnt = cnt + 1
Next i

If cnt < 1 Then
MsgBox "No processes were selected."
Unload frmProcessList
Exit Sub
End If


''''''''''''''''''''redim the array based on number of selections; fill
array with just selections
ReDim arrProcess(1 To cnt, 1 To cnt)

ar = 1
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then
arrProcess(ar, 1) = lbProcess.List(i, 0)
arrProcess(ar, 2) = lbProcess.List(i, 1) '
<<<<<Problem Here
ar = ar + 1
End If
Next i

Unload frmProcessList
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Fill Array from Selected Items in Text Box

Hi John Michl,

Try changing:

ReDim arrProcess(1 To cnt, 1 To cnt)


to

ReDim arrProcess(1 To cnt, 1 To 2)


---
Regards,
Norman


"John Michl" wrote in message
oups.com...
I'm working this out by trial and error and could use some help. I've
got a UserForm with a ListBox called lbProcess. It's RowSource
property is a two column range in a worksheet. If I select two or more
items, it seems to work ok. If I only select one item, I get a
"Subscript Out of Range" error and debug highlights the line marked
below. I assume that I'm not declaring the array correctly. Any
guidance would be appreciated.

Private Sub cmdProcessesPicked_Click()
cnt = 0

'''''''''''''''''''''''''''''''''''''''''determine number of selected
items
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then cnt = cnt + 1
Next i

If cnt < 1 Then
MsgBox "No processes were selected."
Unload frmProcessList
Exit Sub
End If


''''''''''''''''''''redim the array based on number of selections; fill
array with just selections
ReDim arrProcess(1 To cnt, 1 To cnt)

ar = 1
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then
arrProcess(ar, 1) = lbProcess.List(i, 0)
arrProcess(ar, 2) = lbProcess.List(i, 1) '
<<<<<Problem Here
ar = ar + 1
End If
Next i

Unload frmProcessList
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Fill Array from Selected Items in Text Box

Thanks. That did the trick. Arrays confuse me a bit and the examples
I've seen haven't be clear enough for me to understand completely.

- John



Norman Jones wrote:
Hi John Michl,

Try changing:

ReDim arrProcess(1 To cnt, 1 To cnt)


to

ReDim arrProcess(1 To cnt, 1 To 2)


---
Regards,
Norman


"John Michl" wrote in message
oups.com...
I'm working this out by trial and error and could use some help. I've
got a UserForm with a ListBox called lbProcess. It's RowSource
property is a two column range in a worksheet. If I select two or more
items, it seems to work ok. If I only select one item, I get a
"Subscript Out of Range" error and debug highlights the line marked
below. I assume that I'm not declaring the array correctly. Any
guidance would be appreciated.

Private Sub cmdProcessesPicked_Click()
cnt = 0

'''''''''''''''''''''''''''''''''''''''''determine number of selected
items
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then cnt = cnt + 1
Next i

If cnt < 1 Then
MsgBox "No processes were selected."
Unload frmProcessList
Exit Sub
End If


''''''''''''''''''''redim the array based on number of selections; fill
array with just selections
ReDim arrProcess(1 To cnt, 1 To cnt)

ar = 1
For i = 0 To lbProcess.ListCount - 1
If lbProcess.Selected(i) Then
arrProcess(ar, 1) = lbProcess.List(i, 0)
arrProcess(ar, 2) = lbProcess.List(i, 1) '
<<<<<Problem Here
ar = ar + 1
End If
Next i

Unload frmProcessList
End Sub


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
Excel 2002: How to fill up text for like items ? Mr. Low Excel Discussion (Misc queries) 4 September 3rd 08 07:13 PM
ListBox Selected Items into an Array jtp550 Excel Programming 3 September 28th 05 12:44 AM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Add Selected Items Soniya Excel Programming 1 September 28th 03 03:27 PM
Fill Searched array with text [email protected] Excel Programming 3 September 26th 03 03:16 AM


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