gpt4 book ai didi

vba - 带有OR和AND场景的excel vba if语句

转载 作者:行者123 更新时间:2023-12-04 20:12:07 24 4
gpt4 key购买 nike

我有一个电子邮件消息系统,它根据当前记录的国籍选择不同的语言模板。不过,我需要使语言选择动态化,因为最终用户并不总是希望以条目的本国语言发送消息,这意味着例如,如果记录状态为“IT”(意大利)国籍,我想在继续之前检查语言模板是否设置为“事件”,如果模板为“不活动”,则分别默认为 EN(英语)。

'check for nationality and select letter template accordingly
' Use german for DE, AT and CH nationalities
If nationality = "DE" Or nationality = "AT" Or nationality = "CH" Then
Set rng = Sheets("PostStayEmail_DE").Range("A1:B30").SpecialCells(xlCellTypeVisible)
With ActiveWorkbook.Sheets("PostStayEmail_DE")
'do something
End With`

'Use italian for IT nationalities
ElseIf nationality = "IT" Then
Set rng = Sheets("PostStayEmail_IT").Range("A1:B30").SpecialCells(xlCellTypeVisible)
With ActiveWorkbook.Sheets("PostStayEmail_IT")
'do something

End With

现在,我需要的 if 语句是这样的
if (nationality = "DE" or nationality = "AT" or nationality = "CH") _
AND (Range("B5") = "Active") then
'do something

Elseif ... 'check other languages

如何将这些 OR 语句组合为多种语言,同时添加 AND 语句以检查模板是否处于事件状态?

最佳答案

If ((nationality = "DE" Or nationality = "AT" Or nationality = "CH") And Range("B5").Value = "Active") Then
Set Rng = Sheets("PostStayEmail_DE").Range("A1:B30").SpecialCells(xlCellTypeVisible)
With ActiveWorkbook.Sheets("PostStayEmail_DE")
'do something
End With
ElseIf ((nationality = "IT") And Range("B5").Value = "Active") Then
Set Rng = Sheets("PostStayEmail_IT").Range("A1:B30").SpecialCells(xlCellTypeVisible)
With ActiveWorkbook.Sheets("PostStayEmail_IT")
'do something
End With
End If

关于vba - 带有OR和AND场景的excel vba if语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36348253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com