Sub demo()
Dim arr, brr, dic As Object, i%, j%, n%, lastRow%, temp
arr = Sheets("设备明细表").Range("a3").CurrentRegion
Set dic = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
If arr(i, 2) <> "" Then
n = Sheets("设备明细表").Cells(i + 2, 1).MergeArea.Rows.Count
brr = Sheets("设备明细表").Cells(i + 2, 4).Resize(n, 3)
dic(arr(i, 2)) = brr
End If
Next i
lastRow = Sheets("明细").UsedRange.Rows.Count
For i = 1 To lastRow
If Sheets("明细").Cells(i, 1) = "柜号" Then
If dic.exists(Sheets("明细").Cells(i, 2).Value) Then
brr = dic(Sheets("明细").Cells(i, 2).Value)
If UBound(brr) > 15 Then Sheets("明细").Rows(i + 3).Resize(UBound(brr) - 15).Insert
Sheets("明细").Cells(i + 2, 3).Resize(UBound(brr), 3) = brr
End If
End If
Next i
MsgBox "处理完成!"
End Sub
