VBA用户表单消息框

时间:2018-04-12 20:17:40

标签: vba excel-vba excel

我目前有一个消息框的代码

'Message box to ensure that the accounting format equals the loan withdrawl country
If txtloanwithcountry = "England" Then
NumberFormat = "_(£* #,##0.00_);_(£* (#,##0.00);_(£* ""-""??_);_(@_)"

Else

MsgBox "The currency used in the loan withdrawl country must be equal to number format"
End If

然而,我想知道如何输入所有使用英镑的国家,所以当我输入威尔士,苏格兰,北爱尔兰或英格兰时,数字格式是英镑?当我在其他国家/地区键入时,会显示消息框。我曾尝试使用Or Statement,但它不起作用。

1 个答案:

答案 0 :(得分:2)

当您执行Or时,您需要包含整个比较。所以它看起来像

If txtLoanWithCountry = "England" Or txtLoanWithCountry = "Scotland" or txtLoanWithCountry = "Wales" Then

另一种方法是创建一个数组,然后使用Filter函数查看您所在的国家/地区是否在数组中。如果Filter返回Ubound为-1,则表示找不到匹配项。

Dim vaPounds As Variant

'Create the array of countries
vaPounds = Split("England Northern-Ireland Scotland Wales")

If UBound(Filter(vaPounds, txtLoanWithCountry)) = -1 Then
    MsgBox "The currency used in the loan withdrawl country must be equal to number format"
Else
    NumberFormat = "_(£* #,##0.00_);_(£* (#,##0.00);_(£* ""-""??_);_(@_)"
End If