|
|
本帖最后由 niko88819 于 2025-3-21 07:46 编辑
C16
- =niko(B5:B11,H5:H12,G5:G12)
复制代码- Function niko(dataRange As Range, valueRange As Range, searchRange As Range) As Variant
- Dim result() As Variant
- Dim i As Long, j As Long, k As Long
- Dim splitValues As Variant
- Dim tempList As Object
- Dim dict As Object
- Dim maxColumns As Long
- Set dict = CreateObject("Scripting.Dictionary")
- Set tempList = CreateObject("System.Collections.ArrayList")
- For i = 1 To searchRange.Rows.Count
- dict(searchRange.Cells(i, 1).Value) = valueRange.Cells(i, 1).Value
- Next i
- maxColumns = 1
- Dim tempCounts() As Long
- ReDim tempCounts(1 To dataRange.Rows.Count)
- For i = 1 To dataRange.Rows.Count
- tempList.Clear
- splitValues = Split(dataRange.Cells(i, 1).Value, " ")
- For j = LBound(splitValues) To UBound(splitValues)
- If dict.exists(splitValues(j)) Then
- tempList.Add dict(splitValues(j))
- End If
- Next j
- tempCounts(i) = tempList.Count
- If tempList.Count > maxColumns Then maxColumns = tempList.Count
- Next i
- ReDim result(1 To dataRange.Rows.Count, 1 To maxColumns)
- For i = 1 To UBound(result, 1)
- For j = 1 To UBound(result, 2)
- result(i, j) = ""
- Next j
- Next i
- For i = 1 To dataRange.Rows.Count
- tempList.Clear
- splitValues = Split(dataRange.Cells(i, 1).Value, " ")
- For j = LBound(splitValues) To UBound(splitValues)
- If dict.exists(splitValues(j)) Then
- tempList.Add dict(splitValues(j))
- End If
- Next j
- For k = 0 To tempList.Count - 1
- result(i, k + 1) = tempList(k)
- Next k
- Next i
- niko = result
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|