|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下。。。- Sub ykcbf2() '//2024.1.30
- Dim ar, br, d
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set sh = Sheets("模拟重复结果")
- With Sheets("主表")
- fn = .[a1]
- fn1 = .Name
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- ar = .[a1].Range("a1:z" & r)
- End With
- For i = 2 To UBound(ar)
- s = ar(i, 4)
- d(s) = d(s) + 1
- If Not d1.exists(s) Then
- d1(s) = Array(fn1, ar(i, 2), ar(i, 3), s, ar(i, 13), ar(i, 15), ar(i, 26))
- End If
- Next
- With Sheets(fn)
- r = .Cells(.Rows.Count, "a").End(xlUp).Row
- br = .[a1].Range("a1:z" & r)
- End With
- For i = 2 To UBound(br)
- s = br(i, 4)
- d(s) = d(s) + 1
- If Not d2.exists(s) Then
- d2(s) = Array(fn, br(i, 2), br(i, 3), s, br(i, 13), br(i, 15), br(i, 26))
- End If
- Next
- On Error Resume Next
- ReDim brr(1 To 1000, 1 To 8)
- For Each k In d.keys
- t1 = d1(k): t2 = d2(k)
- If d(k) > 1 Then
- If t2 <> Empty Then
- If t1 <> Empty Then
- m = m + 1
- brr(m, 1) = m
- For x = 0 To UBound(t1)
- brr(m, x + 2) = t1(x)
- Next
- m = m + 1
- brr(m, 1) = m
- For x = 0 To UBound(t2)
- brr(m, x + 2) = t2(x)
- Next
- Else
- m = m + 1
- brr(m, 1) = m
- For x = 0 To UBound(t2)
- brr(m, x + 2) = t2(x)
- Next
- End If
- End If
- End If
- Next
- With sh
- .UsedRange.Offset(1).Clear
- With .[a2].Resize(m, 8)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|