A very interesting post a while back from user Herve and replies by Jon Peltier and Richie(UK) talked about initializing a userform from a general module but keeping it hidden so the value could be passed back to the general module.
How can I keep the userform displayed while doing this and display the current listbox.value in a cell in a worksheet instead of the userform unloading and disappearing?
Their code which works to get the one value, but unloads the form and makes it disappear is here.
Passing a variable from a UserForm to a Procedure
Hello All! I do not succeed to pass a variable (Control Button) from a UserForm to a Procedure (in a regular Module). I am declaring the variable as Public and Static, but I get a message that VBA does not support this kind of automation. What's the best way to do that? (I currently save the...
www.mrexcel.com
How can I keep the userform displayed while doing this and display the current listbox.value in a cell in a worksheet instead of the userform unloading and disappearing?
- I would like to have the value of the listbox selection shown in a certain cell and if the selection changes so does the value in the cell.
- Once the user selects the value they want, my intention is to use another button on the userform (action below) to perform an action using the value in that cell.
- If they want to do it again with that value or another, they keep selecting and then pushing action, all the while the form is present.
- I'd like the userform to stay visible until the user pushes a dismiss or 'x' button.
Their code which works to get the one value, but unloads the form and makes it disappear is here.
VBA Code:
'General module:
'Code:
Sub ShowUF()
UserForm1.Show
MsgBox UserForm1.ListBox1.Value
Unload UserForm1
'unload it now that info obtained
End Sub
'Userform code:
'Code:
Private Sub CommandButton1_Click()
UserForm1.Hide
'note Hide not Unload
End Sub
Private Sub UserForm_Initialize()
With ListBox1
.Clear
.AddItem ("Test1")
.AddItem ("Test2")
.AddItem ("Test3")
End With
End Sub