UserForm howto?

  • Thread starter Thread starter AMK4
  • Start date Start date
A

AMK4

Task: I need to write a macro that grabs a particular Range and generate
a userform with a combobox.

Description:
Sheet1 contains names in cells D4:D34
Sheet2 has an action button which when clicked needs to:
- read the names in the afore mentioned range
- generate a pop-up userform that contains the list of names
in a combo box

From there, the user picks a name and hits an Okay (or other button)
which will then use their selection to perform some action.

I've been reading up on creating userforms, but I'm having a hard time
trying to figure out how to create something based on fluid data.
 
Hello AMK4,

There is several ways to attack you problem. But propably the easiest way.
First Insert a UserForm, from VB Editor. Then on the UserForm place
Combobox or or ListBox. In my example I use a ComboBox and name it
'cbox_Name'. Also add the CommandButton to the UserForm. Now place the
following code under the "UserForm_Initialize()" event. This code load
comboBox with the names on Sheet1, cells D4:D34. This event is execute
prior to showing the UserForm. I hope this gives you a starting point. For
your UserForm...

Rick, freezen in Alaska




Private Sub UserForm_Initialize()
Dim ws1 As Worksheet
Dim x As Integer

Set ws1 = Worksheets("Sheet1")

Me.cbox_Name.Clear
Me.cbox_Name.RowSource = ""

For x = 4 To 34
Me.cbox_Name.AddItem ws1.Cells(x, "D").Value
Next x


End Sub
 
Back
Top