Microsoft Office Tutorials and References
In Depth Information
Try It
Next ShoppingListCell
End With
End Sub
While in the UserForm’s module, type the code for CommandButton2 that is the Exit button:
Private Sub CommandButton2_Click()
Unload Me
End Sub
Immediately above the Code window are two drop-down lists. Click the drop-down arrow at
the left belonging to the Object field, and select CommandButton1. That will place these two
statements in the UserForm’s module:
Private Sub CommandButton1_Click()
End Sub
For the first line of code in the CommandButton1 Click event, open a With structure for
Sheet2, which is the destination sheet for selected items:
With Worksheets(“Sheet2”)
Declare variables for ListBox items and NextRow:
Dim intItem As Integer, NextRow As Long
Clear column E of Sheet2 to start your shopping list with a clean slate:
Put a header in cell E1 of Sheet2, to start the list:
.Range(“E1”).Value = “Shopping List”
Define the NextRow variable as 2, because column E was just cleared and the Shopping List
header is in cell E1 with nothing below it:
NextRow = 2
Loop through all items in ListBox1 and if any are selected, list them in turn in column E of
For intItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(intItem) = True Then
.Range(“E” & NextRow).Value = ListBox1.List(intItem)
Add to the 1 NextRow variable to prepare for the next selected item:
NextRow = NextRow + 1
End If
Continue the loop until all ListBox items have been examined:
Search JabSto ::

Custom Search