|
本帖最后由 sparkguo 于 2018-7-26 18:46 编辑
注:以下代码来源:山菊花老师的 正松舒,慢匀稳——太极字典少年班 教程
Sub 第一次练习()
1: CreateObject("SAPI.SpVoice").Speak "VBA£¬oÃϬàû£¡"
2: Dim dic1, dic2, arr(), Brr(), Crr(), m%, n%
3: Set dic1 = CreateObject("Scripting.dictionary")
4: Set dic2 = CreateObject("Scripting.dictionary")
5: arr = Sheet25.Range("l1").CurrentRegion
6: Brr = Sheet25.Range("q1").CurrentRegion
7: Range("a4:d100").ClearContents
8: For i = 4 To UBound(arr)
9: dic1.Add arr(i, 1) & arr(i, 2), ""
10: Next
11: For i = 4 To UBound(Brr)
12: If Not dic1.exists(Brr(i, 2) & Brr(i, 3)) Then
13: If dic2.exists(Brr(i, 2) & Brr(i, 3)) Then
14: n = dic2(Brr(i, 2) & Brr(i, 3))
15: Else
16: m = m + 1
17: dic2.Add Brr(i, 2) & Brr(i, 3), m
18: ReDim Preserve Crr(1 To 4, 1 To m)
19: Crr(1, m) = Brr(i, 2)
20: Crr(2, m) = Brr(i, 3)
21: n = m
22: End If
23: Crr(3, n) = Crr(3, n) + Brr(i, 4)
24: Crr(4, n) = Crr(4, n) + Brr(i, 5)
25: End If
26: Next
27: Range("a4").Resize(m, 4).Value = WorksheetFunction.Transpose(Crr)
End Sub
红色区域的看不懂,n貌似是 关键词对应的项目,那 n = m 是什么意思?这句代码的作用是什么? 按F8 也看不出所以然
|
|