Reputation: 71
I want to create a text box that will store the user's input in the variable "UserChoice". The code for this is as follows:
Dim UserChoice As String
UserChoice= Application.InputBox("Enter Type (A, B, C): ", "Input Box Text", Type:=2)
The options the user can type are "A", "B", and "C". Depending on the user's input, subsequent code will execute using If Then statements.
Is there a way for the user to type two or more of the options and have both of the related box of codes execute?
For example, if the user enters "A, B", is it possible to run both If UserChoice = "A" and If UserChoice = "B"?
Thank you
Upvotes: 0
Views: 5738
Reputation:
Test for any of A, B or C first then execute code by testing for each.
Dim UserChoice As String
UserChoice= ucase(Application.InputBox("Enter Type (A, B, C): ", "Input Box Text", Type:=2))
if not iserror(application.match(left(UserChoice, 1), array("A", "B", "C"), 0)) then
if cbool(instr(1, UserChoice, "A", vbtextcompare)) then
'A is found, run code
end if
if cbool(instr(1, UserChoice, "B", vbtextcompare)) then
'B is found, run code
end if
if cbool(instr(1, UserChoice, "C", vbtextcompare)) then
'C is found, run code
end if
end if
Upvotes: 3