Sub case的使用()
'1、to的使用:相当于“大于等于,且小于等于”。左右边界都包含
score = 100
Select Case score
Case 90 To 100 '等价于[90, 100]
MsgBox "优秀"
Case 60 To 89
MsgBox "及格"
Case Is < 60
MsgBox "不及格"
End Select
'2、逗号的使用:相当于逻辑“或”
my_month = "13"
Select Case my_month
Case "1", "2", "3" '1或2或3
MsgBox my_month & "月属于: 1季度."
Case "4", "5", "6"
MsgBox my_month & "月属于: 2季度."
Case "7", "8", "9"
MsgBox my_month & "月属于: 3季度."
Case "10", "11", "12"
MsgBox my_month & "月属于: 4季度."
Case Else
MsgBox "没有 “" & my_month & "月” 这个月份."
End Select
'3、模糊匹配
str = "FTxxxxS"
Select Case True
Case str Like "DL*" Or str Like "FWT*"
MsgBox str
Case str Like "*T*" And str Like "*S"
MsgBox str
End Select
End Sub
vba,case中的“逻辑或”、使用“to”匹配数字范围、模糊匹配
最新推荐文章于 2025-03-17 15:43:23 发布