|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
给楼主点赞,为了自己方便,我以前也用笨方法写过一个连接二维数组某一行中指定的列的函数,见笑了
'arrSoc 数据源数组(二维)
'iRow 数据源数组需要取值的行
'arrCol 需要取值的列,需用一维数组引用,可使用Array
'delimiter 连接符
Public Function JoinItem(ByVal arrSoc As Variant, ByVal iRow As Long, _
ByVal arrCol As Variant, ByVal delimiter As String) As String
Dim sJoin$, i&, arrSocLB%, arrSocUB%, arrColLB%, arrColUB%
arrSocLB = LBound(arrSoc, 2)
arrSocUB = UBound(arrSoc, 2)
arrColLB = LBound(arrCol)
arrColUB = UBound(arrCol)
If arrColUB - arrColLB > arrSocUB - arrSocLB Then
MsgBox("要连接的个数不能大于数据源数组单行的个数")
End
End If
For i = arrColLB To arrColUB
sJoin = sJoin & delimiter & arrSoc(iRow, arrCol(i))
Next
JoinItem = Mid(sJoin, 2, Len(sJoin))
End Function |
|