Llist boxes, combo boxes in Excel 97 repost

mikefromUK

New Member
Joined
Oct 15, 2002
Messages
42
Hello All

I thought I would post this again to let everyone know that I am trying to solve the problem in Excel 97.

I have written a VBA program that asks for input from the user. I want the user to selection 1 of 3 options. How can I create a dialogue box (either drop down or one consisting of 3 buttons, latter preferred) to do this? I have read all about comboboxes etc but the VBA help does not show how to do this.

Probably just need some examples to show me how it is done.

Cheers

MG
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This should get you started:

1. Press Alt+F11 to go to the Visual Basic Editor.
2. Make sure your workbook is selected in the Project Explorer Window and choose Insert, UserForm from the menu.
3. Add 3 OptionButtons from the Toolbox and change the Captions to what you want.
4. Add 2 CommandButtons from the ToolBox and change the Captions to OK and Cancel respectively.
5. Right click the UserForm and choose View Code.
6. Paste this code into the Code window:

Code:
Private Sub CommandButton1_Click()
    If OptionButton1 Then MsgBox "You chose OptionButton1"
    If OptionButton2 Then MsgBox "You chose OptionButton2"
    If OptionButton3 Then MsgBox "You chose OptionButton3"
    Unload UserForm1
End Sub

Private Sub CommandButton2_Click()
    Unload UserForm1
End Sub

7. Click on your workbook in the Project Explorer window and choose Insert Module from the menu.
8. Paste this code in the Code window:

Code:
Sub ShowForm()
    UserForm1.Show
End Sub
[/CODE}

9. Press F11 to return to your workbook, press Alt+F8, select ShowForm and click OK.

Post back if you need more help.
 
Upvote 0
OK - with you so far but I need to pass back to the main program what the user responsed. I was thinking of making it a fuction rather than a sub. See below.

Private function CommandButton1_Click()
dim option as Integer
If OptionButton1 Then option =1
If OptionButton2 Then option =2
If OptionButton3 Then option =3
Unload UserForm1

CommandButton1_Click = option

End Sub
 
Upvote 0
If you declare your variable at the top of your general module like this:

Public option As Integer

it will be available to all your procedures.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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