PDA

Click to See Complete Forum and Search --> : Problem with multiple selection listbox to cell


nino2882
Jul 7th, 2005, 08:17 AM
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

mikeyc1204
Jul 7th, 2005, 11:15 AM
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.

nino2882
Jul 7th, 2005, 11:26 AM
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!

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.