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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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.
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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