最近有个同事需要编写个宏,Excel-VBA中需要用到类似php中的swith-case的功能,翻了下,将VBA中类似的示例代码列出来供需要的人参考:

Select Case income
Case Is <= 0
profitrank = "<=0"
Case Is <= 5000
profitrank = "0-5千万"
Case Is <= 10000
profitrank = "5千万-1亿"
Case Is <= 20000
profitrank = "1亿-2亿"
Case Is <= 30000
profitrank = "2亿-3亿"
Case Is <= 40000
profitrank = "3亿-4亿"
Case Is <= 50000
profitrank = "4亿-5亿"
Case Is <= 100000
profitrank = "5亿-10亿"
Case Else
profitrank = ">10亿"
End Select

上述代码是判定值的,注意顺序。还有个办法直接判定外部的值。

Select Case true
Case Target.Row > 3 And Target.Row < 10
rem 4-9行
Case Target.Row > 10 And Target.Row < 17
rem 11-16行
Case Else
rem 其他行
End Select

如您从本文得到了有价值的信息或帮助,请考虑扫描文末的二维码对我进行赞赏和鼓励。

与《Excel-VBA-switch的示例》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌