Question: Excel visual basic project. Please i need to know steps of doing this project. or a compite project in excel . Thanks. 1.Open a new

Excel visual basic project. Please i need to know steps of doing this project. or a compite project in excel . Thanks.

1.Open a new workbook and activate Sheet1

2.In column A, enter the items in the cells as you see them displayed below

A

B

1

Milk

2

Eggs

3

4

Fruit

5

6

Steak

7

8

Vegetable

9

Bread

10

Oatmeal

11

12

Potato Chips

13

Beer

14

15

Cheese

16

3.Go to Visual Basic Editor

4.Select your workbook name in the project Explorer, and from the menu bar click Insert -> UserForm and accept its default name of UserForm1.

5.Change UserForms Caption property to Shopping List.

6.Select the UserForm in its design window and if the Toolbox is not visible, click View -> Toolbox.

7.Draw a ListBox on the UserForm and accept its default name of ListBox1. Set its multiSelect property to 1 - fmmultiDelectMulti.

8.Draw a CommandButton on the UserForm below the ListBox and accept its default name of commandButton1. Change its Caption to property to Transfer selected items to Sheet2 column E.

9.Draw another CommandButton on the UserForm below the first CommandButtonm and change its caption property t EXIT. That completes the design of the UserForm.

initialize the event under the UserForm to populate the listBox with items in Column A of Sheet1, ignoring the empty cells.

Private Sub UserForm_Initialize()

Dim LastRow As Long, ShoppingListCell As Range

With Worksheets("Sheet1")

LastRow = .Cells(Rows.Count, 1).End(xlUp).Row

For Each ShoppingListCell In .Range("A1:A" & LastRow)

If Len(ShoppingListCell.Value) > 0 Then _

lstShoppingList.AddItem ShoppingListCell.Value

Next ShoppingListCell

End With

End Sub

11.While in UserForms module type the code for commandButton2 that is the Exit button

12.Immediately above the code window are two drop-down lists. Click the drop-down arrow at the left belonging to the Object field, and selelct commandButton to place these two statements in the UserForms module.

For the first line of code in the CommandButton click event, open a with structure for Sheet2, which is the destination sheet for selected items

With worksheets(Sheet2)

Declare variables for the ListBoxs items and NextRow:

Dim inItem as Integer, NextRow As long

Clear column E of Sheet2 to start your shopping list with a clean slate:

.Columns(5).Clear

Put a header in cell E1 of Sheet2, to start the list:

.Range(E1).Value = Shopping List

Define the NextRow variable as 2, becausecolumn 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 sheet 2

For intItem = 0 To lstShoppingList.ListCount - 1

If lstShoppingList.Selected(intItem) = True Then

.Range("E" & NextRow).Value = lstShoppingList.List(intItem)

Add 1 to the NextRow variable to prepare for the next selected item

Continue the loop until all ListBox items have been examined

Close the with structure for Sheet2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!