Excel VBA 代码,有谁能给个详细注释。
第二行的变量是怎么申明的?1Subaaa()2Dimarr,arr1,i&,j&,dAsObject,d1AsObject,n&3Setd=CreateObject("s...
第二行的变量是怎么申明的?
1 Sub aaa()
2 Dim arr, arr1, i&, j&, d As Object, d1 As Object, n&
3 Set d = CreateObject("scripting.dictionary")
4 Set d1 = CreateObject("scripting.dictionary")
5 arr = Sheets(2).[a1].CurrentRegion
6 For i = 2 To UBound(arr)
7 d(arr(i, 1)) = d(arr(i, 1)) & "," & arr(i, 2)
8 d1(arr(i, 1)) = d1(arr(i, 1)) + 1
9 Next i
10 n = Application.Max(d1.items)
11 Columns("c:iv").ClearContents
12 arr = [a1].CurrentRegion
13 ReDim Preserve arr(1 To UBound(arr), 1 To 2 + n)
14 For i = 2 To UBound(arr)
15 arr1 = Split(Mid(d(arr(i, 2)), 2), ",")
16 For j = 3 To 3 + UBound(arr1)
17 arr(i, j) = arr1(j - 3)
18 Next j
19 Next i
20 [a1].Resize(UBound(arr), UBound(arr, 2)) = arr
21 End Sub 展开
1 Sub aaa()
2 Dim arr, arr1, i&, j&, d As Object, d1 As Object, n&
3 Set d = CreateObject("scripting.dictionary")
4 Set d1 = CreateObject("scripting.dictionary")
5 arr = Sheets(2).[a1].CurrentRegion
6 For i = 2 To UBound(arr)
7 d(arr(i, 1)) = d(arr(i, 1)) & "," & arr(i, 2)
8 d1(arr(i, 1)) = d1(arr(i, 1)) + 1
9 Next i
10 n = Application.Max(d1.items)
11 Columns("c:iv").ClearContents
12 arr = [a1].CurrentRegion
13 ReDim Preserve arr(1 To UBound(arr), 1 To 2 + n)
14 For i = 2 To UBound(arr)
15 arr1 = Split(Mid(d(arr(i, 2)), 2), ",")
16 For j = 3 To 3 + UBound(arr1)
17 arr(i, j) = arr1(j - 3)
18 Next j
19 Next i
20 [a1].Resize(UBound(arr), UBound(arr, 2)) = arr
21 End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询