|
- Sub test()
- Dim r%, i%
- Dim arr, brr, crr(), drr
- Dim d As Object
- Randomize Timer
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a2:c" & r)
- For i = 1 To UBound(brr)
- If Not d.exists(brr(i, 1)) Then
- Set d(brr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- d(brr(i, 1))(i) = Empty
- Next
- End With
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- ReDim crr(1 To UBound(arr), 1 To 1)
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 1)) Then
- drr = d(arr(i, 1)).keys
- x1 = Int(Rnd() * (UBound(drr) + 1))
- x2 = Int(Rnd() * (UBound(drr) + 1))
- If brr(drr(x1), 2) <> empyt Then
- crr(i, 1) = brr(drr(x1), 2) & Space(1) & arr(i, 3)
- Else
- crr(i, 1) = arr(i, 3)
- End If
- If brr(drr(x2), 3) <> Empty Then
- crr(i, 1) = crr(i, 1) & Space(1) & brr(drr(x2), 3)
- End If
- End If
- Next
- .Range("f2").Resize(UBound(crr), 1) = crr
- End With
- End Sub
复制代码 |
|