繁体   English   中英

Excel VBA:具有多个条件的输入框文本

[英]Excel VBA: Input Box Text with multiple criteria

我想创建一个文本框,将用户输入存储在变量“ UserChoice”中。 的代码如下:

Dim UserChoice As String
    UserChoice= Application.InputBox("Enter Type (A, B, C):  ", "Input Box Text", Type:=2)

用户可以键入的选项是“ A”,“ B”和“ C”。 根据用户的输入,后续代码将使用If Then语句执行。

用户是否可以键入两个或多个选项,并执行两个相关的代码框?

例如,如果用户输入“ A,B”,是否可以同时运行UserChoice =“ A”和If UserChoice =“ B”?

谢谢

首先测试A,B或C中的任何一个,然后通过测试每个代码来执行代码。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM