Microsoft Office Tutorials and References
In Depth Information
Try It
Next ShoppingListCell
End With
End Sub
10.
While in the UserForm’s module, type the code for CommandButton2 that is the Exit button:
Private Sub CommandButton2_Click()
Unload Me
End Sub
11.
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
12.
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”)
13.
Declare variables for ListBox items and NextRow:
Dim intItem As Integer, NextRow As Long
14.
Clear column E of Sheet2 to start your shopping list with a clean slate:
.Columns(5).Clear
15.
Put a header in cell E1 of Sheet2, to start the list:
.Range(“E1”).Value = “Shopping List”
16.
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
17.
Loop through all items in ListBox1 and if any are selected, list them in turn in column E of
Sheet2:
For intItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(intItem) = True Then
.Range(“E” & NextRow).Value = ListBox1.List(intItem)
18.
Add to the 1 NextRow variable to prepare for the next selected item:
NextRow = NextRow + 1
End If
19.
Continue the loop until all ListBox items have been examined:
Search JabSto ::




Custom Search