Excel Home
全球知名的Excel资源网站之一

替自定义函数设置可选参数

本文为《别怕,Excel VBA其实很简单(第3版)》随书问题参考答案

Function JoinText(Rng As Range, Optional Txt As String = ",") As String
Dim c As Range
For Each c In Rng
JoinText = JoinText & c.Value & Txt
Next c
JoinText = Left(JoinText, Len(JoinText) - 1)
End Function

或者

Function JoinText(Rng As Range, Optional Txt As Variant) As String
Dim c As Range
If IsMissing(Txt) Then Txt = ","
For Each c In Rng
JoinText = JoinText & c.Value & Txt
Next c
JoinText = Left(JoinText, Len(JoinText) - 1)
End Function

赞(1)
未经允许不得转载:ExcelHome » 替自定义函数设置可选参数
分享到: 更多 (0)

关于我们联系我们
本站特聘法律顾问:李志群律师   沪ICP备11019229号-2

沪公网安备 31011702000001号

征信