Results 1 to 3 of 3

Thread: Problem with multiple selection listbox to cell

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Problem with multiple selection listbox to cell

    Hello all,

    I am having a problem taking the selections from a multiple select enabled listbox and passing it onto an excel cell. I think I have the correct code, but I get an error message at runtime. Here is the code:

    Private Sub testButton_Click()
    Dim tmGasket
    For i% = 0 To lsGasket.ListCount - 1
    If lsGasket.Selected(i%) = True Then
    MsgBox "Item number " & i% & " is selected " & lsGasket.List(i%)
    tmGasket = tmGasket & " , " & lsGasket.List(i%)
    End If
    Next i%
    Cells(locRow, locCol) = tmGasket
    End Sub

    and I get this error:
    Run-time error '1004':
    Application-defined or object defined error.

    I can see the message boxes that pop up, so I know its taking the selections. When I debug it, it points me to the "Cells(locRow, locCol) = tmGasket" line. Am I just assigning it wrong? The excel parts work, I just am not sure what to do now. Any help would be greatly appreciated, thank you.

    -Nino

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Problem with multiple selection listbox to cell

    Check your locRow and locCol variables at the break. If either = 0, Excel will throw RTE 1004. Likewise, if locRow > 256^2 or locCol >256 you'll get the same 1004.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Re: Problem with multiple selection listbox to cell

    Yeah, that explains it. I was running the form by itself, and since its a part of it, the variables were initialized to 0. Seems pretty silly on my part now. Thanks for the help!

    Quote Originally Posted by mikeyc1204
    Check your locRow and locCol variables at the break. If either = 0, Excel will throw RTE 1004. Likewise, if locRow > 256^2 or locCol >256 you'll get the same 1004.

Posting Permissions

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



Click Here to Expand Forum to Full Width