我是靠谱客的博主 醉熏帅哥,最近开发中收集的这篇文章主要介绍VBA实现的Excel Switch函数,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

转自淘财财的博客

“可惜的是excel工作表竟然不知道switch函数,但是老天有眼,excel的VBA函数却可以支持switch,所以有些高手就做了些为国为名的好事”

调用形式
=Switch2(A1<1000,”D”,A1<5000,”C”,A1<10000,”B”,TRUE,”A”)

VBA代码:
Function Switch2(Test1 As String, Result1 As String, _
Optional Test2 As String, Optional Result2 As String, _
Optional Test3 As String, Optional Result3 As String, _
Optional Test4 As String, Optional Result4 As String, _
Optional Test5 As String, Optional Result5 As String, _
Optional Test6 As String, Optional Result6 As String, _
Optional Test7 As String, Optional Result7 As String, _
Optional Test8 As String, Optional Result8 As String, _
Optional Test9 As String, Optional Result9 As String, _
Optional Test10 As String, Optional Result10 As String, _
Optional Test11 As String, Optional Result11 As String, _
Optional Test12 As String, Optional Result12 As String, _
Optional Test13 As String, Optional Result13 As String, _
Optional Test14 As String, Optional Result14 As String)
Switch2 = Switch(Test1, Result1, _
Test2, Result2, _
Test3, Result3, _
Test4, Result4, _
Test5, Result5, _
Test6, Result6, _
Test7, Result7, _
Test8, Result8, _
Test9, Result9, _
Test10, Result10, _
Test11, Result11, _
Test12, Result12, _
Test13, Result13, _
Test14, Result14)
End Function


以Office 2010为例,Alt+F11打开VBA编辑器,点插入>模块可以添加自定义函数。
需要返回整数值的时候,把所有的Result As String替换成Result As Integer。

最后

以上就是醉熏帅哥为你收集整理的VBA实现的Excel Switch函数的全部内容,希望文章能够帮你解决VBA实现的Excel Switch函数所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部