简体   繁体   中英

VBA userform message box

I currently have the following code for a message box

'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

However, I was wondering how I can input all the countries that uses British Pounds, so when I either type in Wales, Scotland, Nothern-Ireland or England, the Number Format is British Pounds? When I type in other countries, the message box shows. I have tried to use Or Statement, but it doesn't work.

When you do an Or you need to include the whole comparison. So it would look like

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

Another method is to create an array, then use the Filter function to see if your country is in the array. If Filter returns a Ubound of -1, it didn't find a match.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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