Option Explicit
Sub 两表间传送()
Dim shtFrom As Worksheet, shtTo As Worksheet
Dim i%, iEnd%, arr(), u%, boxID$, ii%, iBoxCount%
'Dim rngBoxID As Range
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
'我当你的《明细》表没有柜号,靠代码按顺序填写,而且每一个柜号占22行
Set shtFrom = ThisWorkbook.Sheets("设备明细表")
Set shtTo = ThisWorkbook.Sheets("明细")
'iEnd = shtFrom.Range("B65536").End(xlUp).Offset(1, 0).Row - 1
'for each rngBoxID in
'iBoxCount = 0
arr = shtFrom.Range("A3").
网页链接 u = UBound(arr)
With shtTo
For i = 2 To u
If Len(arr(i, 2)) Then
boxID = arr(i, 2)
ii = iBoxCount * 22 + 1
iBoxCount = iBoxCount + 1 '柜号+1
.Cells(ii, 2).Value = boxID
ii = ii + 2
Else
ii = ii + 1
End If
.Cells(ii, 2).Value = arr(i, 3) ' 元件名称
.Cells(ii, 3).Value = arr(i, 4) ' 型号规格
.Cells(ii, 4).Value = arr(i, 5) ' 单位
.Cells(ii, 5).Value = arr(i, 6) ' 数量
Next
End With
End Sub
