首页 > 代码库 > VBA小技巧
VBA小技巧
运用VBA时,可以构造一些函数去实现诸如printf的方便函数。
Public Function printf(mask As String, ParamArray tokens()) As String Dim i As Long For i = 0 To UBound(tokens) mask = Replace(mask, "{" & i & "}", tokens(i)) Next printf = mask End Function Sub test1() cc = genSearchedArr(6554, "a", "b", "e", "f", "g") MsgBox cc End Sub Function genSearchedLines(searchedRow As Integer, ParamArray columns()) As String Dim searchedVal As String Dim i As Long For i = 0 To UBound(columns) If i = 0 Then searchedVal = printf("{0}{1}", columns(i), searchedRow) Else searchedVal = searchedVal & printf("&{0}{1}", columns(i), searchedRow) End If Next genSearchedLines = searchedVal End Function Function genSearchedArr(searchedRow As Integer, ParamArray columns()) As String Dim searchedArr As String Dim i As Long For i = 0 To UBound(columns) If i = 0 Then searchedArr = printf("{0}1:{0}{1}", columns(i), (searchedRow - 1)) Else searchedArr = searchedArr & printf("&{0}1:{0}{1}", columns(i), (searchedRow - 1)) End If Next genSearchedArr = searchedArr End Function
VBA小技巧
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。