Parameters with fixed set of possible values

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

How do I make a subroutine with a parameter that has a fixed set of
possible values? I want something similar to the box that pops up for a
boolean with only 'true' and 'false' options.

Also, is it possible to populate the pop up box with options such as
'red', 'blue' that correspond to values such as '1', '2'?
 
do you mean in the VBE? Where does this box popup with True and False?
 
Aaron,

In Excel 2000 or later, you can use Enum type variables. For
example,

Public Enum MyEnum
Red = 1
Blue = 2
End Enum

Then, declare the argument to the procedure As MyEnum. For
example,

Sub Test(WhatColor As MyEnum)
' your code here
End Sub

Finally, you can use a value of the enum in the code that calls
the procedure.

Test WhatColor:=Blue


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top