|
源码公开:
Function My超级字符连接(查找区域 As Range, 查找值, 连接区域 As Range)
Application.Volatile
Dim 所有字符(), 匹配字符(), 连接字符(), S%, I%, a%
表格Mc = 连接区域.Worksheet.Name
If (查找区域.Columns.Count > 1 And 查找区域.Rows.Count > 1) Or _
(查找区域.Columns.Count = 1 And 查找区域.Rows.Count = 1) Then
My超级字符连接 = "参数不正确"
Exit Function
End If
a = 0
If 查找区域.Columns.Count = 1 Then
所有字符 = WorksheetFunction.Transpose(查找区域)
连接字符 = WorksheetFunction.Transpose(连接区域)
S = UBound(所有字符)
For I = 1 To S
If 所有字符(I) = 查找值 Then
a = a + 1
ReDim Preserve 匹配字符(1 To a)
匹配字符(a) = 连接字符(I)
End If
Next
End If
' ------------------------------------------------
If 查找区域.Rows.Count = 1 Then
For Each 匹配单元格 In 查找区域
If 匹配单元格.Value = 查找值 Then
a = a + 1
ReDim Preserve 匹配字符(1 To a)
匹配字符(a) = Sheets(表格Mc).Cells(连接区域.Row, 匹配单元格(1, 1).Column)
End If
Next
End If
My超级字符连接 = Join(匹配字符, ",")
End Function
欢迎给点意见 我好改进 我不喜欢用&这个字符 特意用数组来写的 |
|