+ Reply to Thread
Results 1 to 3 of 3

Fill Array from Selected Items in Text Box

  1. #1
    John Michl
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <waxwing1@gmail.com> wrote in message
    news:1149284799.419425.259470@u72g2000cwu.googlegroups.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. #3
    John Michl
    Guest

    Re: 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" <waxwing1@gmail.com> wrote in message
    > news:1149284799.419425.259470@u72g2000cwu.googlegroups.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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1