VBA用户表单消息框

VBA用户表单消息框,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 lo

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

'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语句,但不起作用

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

If txtLoanWithCountry = "England" Or txtLoanWithCountry = "Scotland" or txtLoanWithCountry = "Wales" Then
另一种方法是创建一个数组,然后使用Filter函数查看您的国家是否在数组中。如果筛选器返回-1的Ubound,则未找到匹配项

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

在执行
时,需要包含整个比较。所以看起来像

If txtLoanWithCountry = "England" Or txtLoanWithCountry = "Scotland" or txtLoanWithCountry = "Wales" Then
另一种方法是创建一个数组,然后使用Filter函数查看您的国家是否在数组中。如果筛选器返回-1的Ubound,则未找到匹配项

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

国家列表位于何处?当您说您试图使用Or语句但不起作用时,Or语句是什么样子的(因为它应该起作用)?我没有创建国家列表,因为这将被输入文本框。然后我有:If txtloanwithcountry=“英格兰或苏格兰或威尔士或北爱尔兰”然后你可能应该把你的问题包括在你尝试过的东西里。FWIW VBA看到的所有表达式都是
如果txtloadwithcountry=“some very long string”
。国家列表位于何处?当您说您试图使用Or语句但无效时,Or语句看起来是什么样子(因为它应该起作用)?我没有创建国家列表,因为这是要在文本框中输入的。然后我有:如果txtloanwithcountry=“英格兰或苏格兰或威尔士或北爱尔兰”,那么您可能应该将您的问题包括您尝试过的内容。FWIW如果txtloadwithcountry=“一些相当长的字符串”
,VBA看到的所有表达式都是