本帖最后由 yzyyyyyyy 于 2024-9-13 18:16 编辑
感谢大师热心帮助,还是大师写- Sub test5() '
- Dim r%, i%, c%, j%, m%, n%
- Dim arr, brr(1 To 17, 1 To 3)
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- m = 1
- bj = Sheets("目标表5").Range("A5:A" & Sheets("目标表5").[a65536].End(3).Row)
- For Each x In bj
- m = m + 1
- d(x) = m
- Next
- With Worksheets("原始表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If d.Exists(arr(i, 3)) Then '
- m = d(arr(i, 3))
- brr(1, 1) = brr(1, 1) + 1
- brr(m, 1) = brr(m, 1) + 1
- If arr(i, 6) = "男" Then
- brr(1, 2) = brr(1, 2) + 1
- brr(m, 2) = brr(m, 2) + 1
- Else
- brr(1, 3) = brr(1, 3) + 1
- brr(m, 3) = brr(m, 3) + 1
- End If
- End If
- Next
- End With
- With Worksheets("目标表5") '
- .Range("B4").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
- Sub test6() '
- Dim r%, i%, c%, j%, m%, n%
- Dim arr, brr(1 To 17, 1 To 20)
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- m = 1
- 'bj = Sheets("目标表6").Range("C3:E3")
- With Sheets("目标表6")
- bj = .Range(.Cells(3, 3), .Cells(3, .Cells(3, .Columns.Count).End(xlToLeft).Column))
- End With
- For Each x In bj
- m = m + 1
- d(x) = m
- Next
- With Worksheets("原始表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If d.Exists(arr(i, 3)) Then '
- m = d(arr(i, 3))
- brr(1, 1) = brr(1, 1) + 1
- brr(1, m) = brr(1, m) + 1
- If arr(i, 6) = "男" Then
- brr(2, 1) = brr(2, 1) + 1
- brr(2, m) = brr(2, m) + 1
- Else
- brr(3, 1) = brr(3, 1) + 1
- brr(3, m) = brr(3, m) + 1
- End If
- End If
- Next
- End With
- With Worksheets("目标表6") '
- .Range("B4").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |