Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormList box populates wrong column and doubes 1st entry

Status
Not open for further replies.

striveforexcelence

Technical User
Oct 5, 2005
34
US
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
 
I only want it to be able to go in b and c
Replace this:
Selection.Cells(1)
with this:
Selection.EntireRow.Cells(2)
And this:
Selection.Cells(1).Offset(0, 1)
by this:
Selection.EntireRow.Cells(3)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you PVH I made the changes. Now it is duplicating each entry so that the first entry appears exactly the same in row 1 and 2 and the next 3 and 4 and so on.

The code doesnt seem to make it populate only columns b and c it is able to populate wherever the cursor is. Am I misunderstanding something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top