参数:
-
- Code :查询的内容
- Zone :查询的区域
- ColumnIndex :指定返回列的序号
- Splitor :行分隔符
'连接字符串,类似PHONETIC,但是可以添加分隔符
Function ConnectString(Zone As range, Splitor As String)
Dim columnCount As Long, rowsCount As Long
Dim resultStr As String
Dim i As Integer, j As Integer
columnCount = Zone.Columns.Count
rowsCount = Zone.Rows.Count
'默认分隔符为 ;
If Splitor = "" Then
Splitor = ";"
End If
For i = 1 To columnCount Step 1
For j = 1 To rowsCount Step 1
If Zone.Cells(j, i) <> "" Then
'第一个匹配项,不添加分隔符
If resultStr <> "" Then
resultStr = resultStr & Splitor
End If
resultStr = resultStr & Zone.Cells(j, i)
End If
Next
Next
ConnectString = resultStr
End Function