|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 cnmlgb9998 于 2024-7-18 19:08 编辑
不过,四年没碰VBA 了,基本语句,我都忘光了。
贴上我的原生代码。残念。。。。。。
- Sub test()
- Set dic = CreateObject("scripting.dictionary")
- arr = Range("A2:C" & Cells(Rows.Count, 1).End(xlUp).Row)
- brr = Range("E2:E11")
- Dim drr()
- ReDim grr(1 To UBound(brr), 1 To 2)
- For i = 1 To UBound(arr)
- dm = arr(i, 1)
- xb = arr(i, 2)
- en = arr(i, 3)
- dic(dm) = IIf(dic(dm) = "", en & "," & xb, dic(dm) & "/" & en & "," & xb)
- Next
-
- For Each br In brr
- Do
- If dic.exists(br) Then
- crr = Split(dic(br), "/")
-
- For Each cr In crr
- If Split(cr, ",")(1) = "儿子" Then
- male = male + 1
-
- Else
- female = female + 1
-
- End If
- n = n + 1
- ReDim Preserve drr(1 To n)
- drr(n) = Split(cr, ",")(0)
- Next
-
- End If
-
- m = m + 1
- If m <= n Then
- br = drr(m)
- End If
-
- Loop While m <= n
- s = s + 1
- grr(s, 1) = male
- grr(s, 2) = female
- male = 0
- female = 0
- n = 0
- m = 0
-
-
-
- Next
- [F2:G11].ClearContents
- [F2].Resize(UBound(grr), 2) = grr
-
- End Sub
复制代码
|
|