码迷,mamicode.com
首页 > 编程语言 > 详细

VBA小技巧

时间:2017-08-13 20:12:22      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:sub   class   string   sea   运用   int   amp   实现   row   

运用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小技巧

标签:sub   class   string   sea   运用   int   amp   实现   row   

原文地址:http://www.cnblogs.com/kid551/p/7354424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!