'猜一个,假设C列有序
'按顺序写入未作随机分配,当然也可随机需再处理一下
Option Explicit
Sub test()
Dim arr, i, j, k, n, brr, pos
With Sheets("sheet3")
arr = .Range("a2:f" & .Cells(Rows.Count, "a").End(xlUp).Row)
End With
brr = Sheets("sheet4").[c4].CurrentRegion
For i = 1 To UBound(arr, 1): arr(i, 6) = vbNullString: Next
For j = 3 To 5
For i = 1 To UBound(arr, 1)
If arr(i, 3) = brr(1, j) Then pos = i: Exit For
Next
n = 0
For i = 3 To UBound(brr, 1)
If IsNumeric(brr(i, j)) Then
For k = 1 To brr(i, j)
n = n + 1
arr(pos + n - 1, 6) = brr(i, 1)
Next
End If
Next i, j
Sheets("sheet3").[a2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub |