PDA

View Full Version : Solved: Move Row by Row in a listbox???



Ben File
03-11-2010, 07:36 PM
Having trouble!!!!!!!
1.Entering info in the INFO1,INFO2,INFO3 text boxes
2.Add is adding info to sheet 1 and the list box
3.Print is adding info from list box to sheet 2 first empty cell


Problem:
When adding multiple items example: clicking add button 2 times gives me 2 rows in the list box.
Can not figure out how to add something to tell the list box to move to the next row in the list box and copy info to the next empty cell of sheet 2.

I hope this explains it???

Thank You in advance.

Private Sub cmdAdd_Click()
ActiveWorkbook.Sheets("Sheet1").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = txtINFO1.Value

ActiveCell.Offset(0, 1) = txtINFO2.Value

ActiveCell.Offset(0, 2) = txtINFO3.Value

'pass the info added to listbox
Dim x As Variant
x = ActiveCell.Value & Chr(32) & ActiveCell.Offset(0, 1) & Chr(32) & ActiveCell.Offset(0, 2)
ListBox1.AddItem x
'counts the number of lines add to list box
lblRecCount.Caption = ListBox1.ListCount & Chr(32) & "records added."
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdPrint_Click()
'If the Item in Listbox1 is checked then copy checked info to first empty cell in sheet2
ActiveWorkbook.Sheets("Sheet2").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True
'PROBLEM***************************

ActiveCell.Value = UserForm1.ListBox1.List

'PROBLEM***************************
'HOW CAN YOU MOVE ROW BY ROW IN THE LISTBOX!!!!

End Sub


Private Sub UserForm_Initialize()
ActiveWorkbook.Sheets("Sheet1").Activate
txtINFO1.Value = ""
txtINFO2.Value = ""
txtINFO3.Value = ""
End Sub

domfootwear
03-11-2010, 08:11 PM
Having trouble!!!!!!!
1.Entering info in the INFO1,INFO2,INFO3 text boxes
2.Add is adding info to sheet 1 and the list box
3.Print is adding info from list box to sheet 2 first empty cell


Problem:
When adding multiple items example: clicking add button 2 times gives me 2 rows in the list box.
Can not figure out how to add something to tell the list box to move to the next row in the list box and copy info to the next empty cell of sheet 2.

I hope this explains it???

Thank You in advance.

Private Sub cmdAdd_Click()
ActiveWorkbook.Sheets("Sheet1").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = txtINFO1.Value

ActiveCell.Offset(0, 1) = txtINFO2.Value

ActiveCell.Offset(0, 2) = txtINFO3.Value

'pass the info added to listbox
Dim x As Variant
x = ActiveCell.Value & Chr(32) & ActiveCell.Offset(0, 1) & Chr(32) & ActiveCell.Offset(0, 2)
ListBox1.AddItem x
'counts the number of lines add to list box
lblRecCount.Caption = ListBox1.ListCount & Chr(32) & "records added."
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdPrint_Click()
'If the Item in Listbox1 is checked then copy checked info to first empty cell in sheet2
ActiveWorkbook.Sheets("Sheet2").Activate

Range("A1").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True
'PROBLEM***************************

ActiveCell.Value = UserForm1.ListBox1.List

'PROBLEM***************************
'HOW CAN YOU MOVE ROW BY ROW IN THE LISTBOX!!!!

End Sub


Private Sub UserForm_Initialize()
ActiveWorkbook.Sheets("Sheet1").Activate
txtINFO1.Value = ""
txtINFO2.Value = ""
txtINFO3.Value = ""
End Sub

Use this code for cmdPrint Button


Private Sub cmdPrint_Click()
Dim lItem As Long
For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
Sheet2.Range("A65536").End(xlUp)(2, 1) = ListBox1.List(lItem)

ListBox1.Selected(lItem) = False
End If
Next
Unload Me

End Sub

Ben File
03-13-2010, 12:37 PM
THANKS! works fine.