excel vba using

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA - Using Combo Box Selection

Excel VBA - Using Combo Box Selection

resolvedResolved · High Priority · Version 2010

Christopher has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course

Excel VBA - Using Combo Box Selection

I am trying to put some of my learning from the VBA course into action and struggling to call different routines based on the selection in a combo box.

The combo box is populated with the following options which works fine:

Private Sub UserForm_Initialize()
SelectReport.AddItem "********** Select a Report **********"
SelectReport.AddItem "Lost to Follow-Up"
SelectReport.AddItem "Intervention Type Missing"
SelectReport.AddItem "Intervention Setting Missing"
SelectReport.AddItem "Ethnicity Missing"
SelectReport.ListIndex = 0

End Sub


I then try to use this a bit later on when a button is clicked:

Sub ProduceReports()

If SelectReport = "Lost to Follow-Up" Then
Call LostToFUp
ElseIf SelectReport = "Intervention Type Missing" Then
Call InterventionTypeMissing
ElseIf SelectReport = "Intervention Setting Missing" Then
Call InterventionSettingMissing
ElseIf SelectReport = "Ethnicity Missing" Then
Call EthnicityMissing
Else: MsgBox "Please select a report from the drop down box before pressing the Run Report button"
End If

End Sub


I have tries using listIndex but cant get that to work either. I just ge the message box everytime. I have tried putting a msgbox before the IF to show SelectReport and get a blank so I am guessing the statement doesn't work as I haven't got anything stored as a variable for SelectReport but not sure how to resolve this.

Any help would be appreciated.

RE: Excel VBA - Using Combo Box Selection

Hi Christopher

Thanks for getting in touch. I can't see your full module and how it hooks together, but assuming you run ProduceReports outside of the form; does the code know what "SelectReport" is?

Here's a way to test it: it sounds like you have a Run Report button on your userform. Why don't you copy the IF statement, double-click your button and paste the code into there?

It may be the Sub can't 'see' the contents of the form. If this is the case you could prefix references to SelectReport with the name of the form (e.g. UserForm1.SelectReport = ...)

I hope this helps. Give that a try and let me know how you get on.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Excel VBA - Using Combo Box Selection

Gary, thanks for your response. I struggled with this but was able to store the selection as a variable which I made public.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Sum Up All the Values in A Column

If you want to quickly calculate the Summed values of all cells in a column in Excel 2003 normally you would use the SUM formula. (eg if you wanted to calculate the values in Column C rows 10 to 25) the formula would be:

=SUM(C10:C25)

However, if you keep adding values to column C you would keep having to modify the above SUM formula which can get quite annoying.

To get around this you can sum all the values in a column using the following formula:

=SUM(COLUMN:COLUMN)

Which, in our example, would be:

=SUM(C:C)

NOTE You cannot place this formula in column C, or else Excel 2003 will show a circular reference error.

The formula must be placed in any other column, EXCEPT the one being calculated.

View all Excel hints and tips


Server loaded in 0.08 secs.