|
楼上附件已更新:
- Sub Test()
- Dim shSource As Worksheet, shResult As Worksheet, arr As Variant
- Dim rgResult As Range, strTemp As String, strSplit() As String
- Dim lngRow As Long, lngCol As Long
- Dim objDic As Object, strKey As String, strItem As String
- Dim blIsData As Boolean, lngCurRow As Long
-
- Set shSource = Sheets("Sheet1")
- Set shResult = Sheets("Sheet2")
- strTemp = shSource.UsedRange.Address(0, 0)
- strTemp = Split(strTemp, ":")(1)
- arr = shSource.Range("A1:" & strTemp)
- Set objDic = CreateObject("Scripting.Dictionary")
-
- For lngCol = 2 To UBound(arr, 2)
- For lngRow = 1 To UBound(arr)
- If arr(lngRow, 1) = "Test" Then
- strKey = arr(lngRow, lngCol)
- strKey = Trim(strKey)
- ElseIf arr(lngRow, 1) = "LOT No." Then
- blIsData = True
- lngCurRow = lngRow
- ElseIf arr(lngRow, 1) = "" Then
- blIsData = False
- End If
-
- If blIsData = True And lngRow > lngCurRow Then
- strItem = arr(lngRow, lngCol)
- strItem = Trim(strItem)
- If strItem <> "" Then objDic(strKey) = objDic(strKey) & "," & strItem
- End If
- Next
- Next
-
- Set rgResult = shResult.Range("B2")
- rgResult.Resize(1, objDic.Count) = objDic.keys
-
- arr = rgResult.Resize(1, objDic.Count)
-
- For lngCol = LBound(arr, 2) To UBound(arr, 2)
- strKey = arr(1, lngCol)
- strItem = objDic(strKey)
- strTemp = Mid(strItem, 2)
- strSplit = Split(strTemp, ",")
- rgResult.Offset(1, lngCol - 1).Resize(UBound(strSplit) + 1, 1) = Application.WorksheetFunction.Transpose(strSplit)
- Next
-
- MsgBox "OK"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|