|
- Option Explicit
- Dim arrResult As Variant
- Sub Test()
- Dim arrSource As Variant
- Dim lngRows As Long, lngRow As Long
- Dim lngCount As Long
- Dim strID As String, strOriginator As String
-
- lngRows = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
- arrSource = Sheet1.Range("A2:B" & lngRows)
-
- ReDim arrResult(1 To 2, 1 To 1)
- arrResult(1, 1) = "专利代码"
- arrResult(2, 1) = "发明人"
- lngCount = 1
-
- For lngRow = 1 To lngRows - 1
- strID = arrSource(lngRow, 1)
- strOriginator = arrSource(lngRow, 2)
- myPair strID, strOriginator, lngCount, arrResult
- Next
-
- arrResult = Application.WorksheetFunction.Transpose(arrResult)
- Sheet1.Range("F1").Resize(UBound(arrResult), 2) = arrResult
- End Sub
- Function myPair(strID As String, strVal As String, ByRef lngCount As Long, ByRef arrResult As Variant) As Boolean
- Dim strTemp() As String
- Dim intR1 As Integer, intR2 As Integer
- Dim intCount As Integer, intID As Integer
-
- strTemp = Split(strVal, ";")
- intCount = UBound(strTemp)
-
- If intCount = 0 Then
- myPair = False
- Exit Function
- End If
-
- For intR1 = 0 To intCount - 1
- For intR2 = intR1 + 1 To intCount
- lngCount = lngCount + 1
- ReDim Preserve arrResult(1 To 2, 1 To lngCount)
- arrResult(1, lngCount) = strID
- arrResult(2, lngCount) = strTemp(intR1) & ";" & strTemp(intR2)
- Next
- Next
-
- End Function
复制代码 |
|