|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 说不好 于 2017-12-20 13:49 编辑
初学者参与一下试试
- Option Explicit
- Option Base 1
- Public pp As Integer, d As Object
- Sub aa()
- Dim i As Integer, s As String, br(), j As Integer, ar, k As Integer
- pp = 0
- Range("c2:d10000").ClearContents
- ar = Sheets("题目").Range("a2:c" & Sheets("题目").[a65536].End(3).Row)
- Set d = CreateObject("Scripting.Dictionary")
- For i = 1 To UBound(ar)
- s = "": j = 0
- If ar(i, 1) = Cells(2, 1) Then
- s = ar(i, 1) & "-" & ar(i, 2)
- If Not d.Exists(s) Then
- pp = pp + 1
- d(s) = pp
- ReDim Preserve br(3, pp)
- br(1, pp) = ar(i, 3)
- br(2, pp) = s
- If ar(i, 2) <> Cells(2, 2) Then br(3, pp) = ar(i, 2) Else br(3, pp) = "止"
- j = 1
- End If
- End If
- If ar(i, 2) = Cells(2, 1) Then
- s = ar(i, 2) & "-" & ar(i, 1)
- If Not d.Exists(s) Then
- pp = pp + 1
- d(s) = pp
- ReDim Preserve br(3, pp)
- br(1, pp) = ar(i, 3)
- br(2, pp) = s
- If ar(i, 1) <> Cells(2, 2) Then br(3, pp) = ar(i, 1) Else br(3, pp) = "止"
- j = 1
- End If
- End If
- If j = 1 Then
- BB br, ar
- End If
- Next
- If pp > 0 Then
- ReDim cr(1 To pp, 1 To 2)
- k = 0
- For i = 1 To pp
- If br(3, i) = "止" Then
- k = k + 1
- cr(k, 1) = br(1, i)
- cr(k, 2) = br(2, i)
- End If
- Next
- If k > 0 Then [c2].Resize(k, 2) = cr
- End If
- Set d = Nothing
- End Sub
- Sub BB(br(), ar)
- Dim i As Integer, j As Integer, k As Integer, s As String
- For i = 1 To UBound(br, 2)
- For j = 1 To UBound(ar)
- If (InStr(br(2, i), ar(j, 1)) = 0 Or InStr(br(2, i), ar(j, 2)) = 0) And (ar(j, 1) = br(3, i) Or ar(j, 2) = br(3, i)) Then
- s = br(2, i) & "-" & IIf(ar(j, 1) = br(3, i), ar(j, 2), ar(j, 1))
- k = br(1, i)
- If Not d.Exists(s) Then
- pp = pp + 1
- d(s) = pp
- ReDim Preserve br(3, pp)
- br(1, pp) = ar(j, 3) + k
- br(2, pp) = s
- If ar(j, 1) = br(3, i) Then
- If ar(j, 2) <> Cells(2, 2) Then br(3, pp) = ar(j, 2) Else br(3, pp) = "止"
- End If
- If ar(j, 2) = br(3, i) Then
- If ar(j, 1) <> Cells(2, 2) Then br(3, pp) = ar(j, 1) Else br(3, pp) = "止"
- End If
- BB br, ar
- End If
- End If
- Next
- Next
- End Sub
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
|