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
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.
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.