striveforexcelence
Technical User
I have a user form list box. The end user chooses an item. The item is then autopopulated into the first and second column of the first available row. My problem is this. The item is places into whatever column the cursor happened to end in ie., if the user left the cursor in colum g the list box sends the item and cost to g and h. I only want it to be able to go in b and c. Also, for some reason, on only the first selection it enters two of the same items in two different rows?????
Here is the code I used. Does anyone know where I messed up the code?
thank you very much!
Private Sub CommandButton1_Click()
'if the listindex of listbox equals -1 ... nothing selected
If lstSelection.ListIndex = -1 Then
MsgBox "No item selected", vbExclamation
Exit Sub
End If
Range("SelectionLink") = lstSelection.ListIndex + 1
Selection.Cells(1) = Worksheets("HipProducts").Range("D1")
Selection.Cells(1).Offset(0, 1) = Worksheets("HipProducts").Range("E1")
Dim iLastRow As Long
With ActiveSheet
iLastRow = Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Cells(iLastRow, 2).Value = Selection.Cells(1)
Cells(iLastRow, 3).Value = Selection.Cells(1).Offset(0, 1)
Unload Me
End With
End Sub
Here is the code I used. Does anyone know where I messed up the code?
thank you very much!
Private Sub CommandButton1_Click()
'if the listindex of listbox equals -1 ... nothing selected
If lstSelection.ListIndex = -1 Then
MsgBox "No item selected", vbExclamation
Exit Sub
End If
Range("SelectionLink") = lstSelection.ListIndex + 1
Selection.Cells(1) = Worksheets("HipProducts").Range("D1")
Selection.Cells(1).Offset(0, 1) = Worksheets("HipProducts").Range("E1")
Dim iLastRow As Long
With ActiveSheet
iLastRow = Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Cells(iLastRow, 2).Value = Selection.Cells(1)
Cells(iLastRow, 3).Value = Selection.Cells(1).Offset(0, 1)
Unload Me
End With
End Sub