|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 不重复月份数()
- Dim d As Object, d1 As Object, d2 As Object, i%, Arr
- Set d = CreateObject("scripting.dictionary") '月份&省份
- Set d1 = CreateObject("scripting.dictionary") '不重复月份数\
- Set d2 = CreateObject("scripting.dictionary") '信息总数
- Set d3 = CreateObject("scripting.dictionary") '期初数\最终数组
- Arr = [A1].CurrentRegion.Value
- For i = 2 To UBound(Arr)
- If Not d.Exists(Month(Arr(i, 1)) & Arr(i, 2)) Then
- d(Month(Arr(i, 1)) & Arr(i, 2)) = 0
- d1(Arr(i, 2)) = d1(Arr(i, 2)) + 1
- d3(Arr(i, 2)) = 0
- End If
- d2(Arr(i, 2)) = d2(Arr(i, 2)) + 1
- Next
- Range("D2").CurrentRegion.Offset(1).ClearContents
- Range("D2").Resize(d1.Count, 1) = Application.Transpose(d1.Keys)
- Range("E2").Resize(d1.Count, 1) = Application.Transpose(d1.Items)
- Range("F2").Resize(d1.Count, 1) = Application.Transpose(d2.Items)
- Arr = Sheets("期初").[A1].CurrentRegion.Value
- For i = 2 To UBound(Arr)
- If d3.Exists(Arr(i, 1)) Then d3(Arr(i, 1)) = 1
- Next
- Range("G2").Resize(d1.Count, 1) = Application.Transpose(d3.Items)
- For Each Arr In d1.Keys
- d3(Arr) = d3(Arr) * 2 + d2(Arr) + d3(Arr)
- Next
- Range("J2").CurrentRegion.Offset(1).ClearContents
- Range("J2").Resize(d1.Count, 1) = Application.Transpose(d1.Keys)
- Range("K2").Resize(d1.Count, 1) = Application.Transpose(d3.Items)
- End Sub
复制代码 |
|