user form listbox

Qroozn

Well-known Member
Joined
Mar 12, 2002
Messages
543
I'm a newie to user forms.

I have a form Userform1 (which shows up on startup of my program)
In it i have a listbox : repcode

I want the listbox :repcode to list the values of the range in sheet "hidden" ranges "a3:a14"

then i want to save this value to hidden!a1

I am an idiot at this.. any help is greatly appreciated.

Thanks dudes!
Colin
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
First name the range to be shown in the list box, let's say MyList. Then in the properties window for the list box set RowSource to MyList.

Then add a command button to the user form.Assuming it is called CommandButton1, paste this code into the user form module:

Code:
Private Sub CommandButton1_Click()
    Dim RowNo As Integer
    Dim Item
    RowNo = repcode.ListIndex
    Item = WorksheetFunction.Index(Range("MyList"), RowNo, 1)
    Sheets("Hidden").Range("A1") = Item
End Sub

Now the text of the selected item will be placed in cell A1 whenever the command button is clicked.

To dismiss the user form when the button is clicked add this as the last line of code:

Code:
Unload UserForm1

Replae UserForm1 with whatever your form is called.
 

Qroozn

Well-known Member
Joined
Mar 12, 2002
Messages
543
when i open the properties window for the list box set RowSource to MyList. i get the error "could not set the rowsource property. Invalid property value"

what did i do wrong?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Select range A3:A14 on your worksheet and choose Insert, Name, Define from the menu. Type MyList in the Names box. Then try setting the RowSource property.
 

Forum statistics

Threads
1,143,640
Messages
5,719,984
Members
422,256
Latest member
downeybm

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
Top