VBA - Userform continous/dependent

Is_REF

New Member
Joined
Feb 22, 2019
Messages
10
Hello!
I am playing for first time with userforms in VBA. I am trying to have 2 users forms: the first one to select a group of rows ("modules") to be deleted, and the second one to confirm the deletion. I want to see the result of the selection in the first user form in the second user form:

Userform1:

Private Sub CommandButton1_Click()
Range("BB8") = ListBox.Value --> the selection of the user from a list is pasted in cell BB8
UserForm1.Hide
UserForm2.Show


End Sub

Userform 2:
I have use a Listbox for showing the result of question 1:

Private Sub UserForm_initialize()
ListBox.AddItem Worksheets("Commercial").Range("BB8").Value
End Sub

So this works the 1st time I run the macro, but the second time I try to run it the ListBox for the Userfrom2 is equal to the selection made at the first time, so it is not changing, eventhought the value in the cell BB8 has change.
Some knows what I am missing?

Thanks!
IS
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What do you mean by ... this
So this works the 1st time I run the macro, but the second time I try to run it
Do you mean ...
after I press CommandButton1 in UserForm1

Perhaps (amend to the name of your ListBox)
Code:
  ListBox.AddItem Worksheets("Commercial").Range("BB8").Value
  ListBox.ListIndex = ListBox1.ListCount - 1

UserForm2 is hidden from view by the command button - UserForm_Initialize is not triggered when reactivated
Value can be refreshed when reactivated by placing above code in UserForm_Activate()

Do you need a ListBox in UserForm2 or would a TextBox suffice
- a listbox is useful if you want to be able to select from several values
- a TextBox is adequate for latest value only
Code:
TextBox1.Value = Worksheets("Commercial").Range("BB8").Value
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top