|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师,我采用一个字典反复使用,配合数组嵌套也可以实现这个汇总功能了。。
- Sub kuangben8()
- Dim arr, m%, n%, i%, j%, brr, crr, drr, err, s, k%, l%
- Dim dic As Object
- Set dic = CreateObject("Scripting.Dictionary")
- arr = Range("A1").CurrentRegion
- For m = 2 To UBound(arr, 1)
- dic(arr(m, 1)) = "" '获取不重复的会员昵称
- Next
- brr = dic.keys
- dic.RemoveAll '清空字典内容,后续继续使用
- ReDim crr(1 To UBound(brr) + 1)
- For m = 1 To UBound(brr) + 1
- For n = 2 To UBound(arr, 1)
- If arr(n, 1) = brr(m - 1) Then
- dic(arr(n, 2)) = ""
- End If
- Next
- crr(m) = dic.keys '将关键字赋给数组的某一个元素,此时一个元素也是一个数组。
- dic.RemoveAll '清空字典内容,后续继续使用。
- Next
- ReDim drr(1 To UBound(brr) + 1)
- For m = 1 To UBound(crr)
- drr(m) = crr(m)
- For n = 1 To UBound(crr(m)) + 1 '对数组的一个元素(也是数组)进行循环。
- For i = 1 To UBound(brr) + 1
- For j = 2 To UBound(arr, 1)
- If arr(j, 1) = brr(i - 1) Then
- If arr(j, 2) = crr(m)(n - 1) Then
- dic(arr(j, 3)) = ""
- End If
- End If
- Next j
- If dic.Count > 0 Then
- drr(m)(n - 1) = dic.keys
- End If
- Rem 采用数组嵌套的方式实现多维数组的功能!
- dic.RemoveAll '清空字典内容,后续继续使用。
- Next i
- Next n
- Next m
- j = 0
- ReDim err(1 To UBound(brr) + 1, 1 To 2)
- For m = 1 To UBound(brr) + 1
- j = j + 1
- s = "您的订单发货快递为:"
- For n = 1 To UBound(crr(m)) + 1
- s = s & "订单号:" & crr(m)(n - 1) & ","
- For i = 1 To UBound(drr(m)(n - 1)) + 1
- s = s & drr(m)(n - 1)(i - 1) & ":"
- For k = 2 To UBound(arr)
- If arr(k, 1) = brr(m - 1) And arr(k, 2) = crr(m)(n - 1) And arr(k, 3) = drr(m)(n - 1)(i - 1) Then
- l = l + 1
- s = s & IIf(l <> 1, "、", "") & arr(k, 4)
- End If
- Next
- s = s & ";"
- l = 0
- Next
- Next
- err(m, 1) = brr(m - 1)
- err(m, 2) = Left(s, InStrRev(s, ";") - 1) & "。"
- Next
- Range("F2:G" & Cells(Rows.Count, 7).End(3).Row + 1).ClearContents
- Range("F2").Resize(UBound(err, 1), 2) = err
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|