請教大大
A欄 B欄 C欄 D欄
2 12
3 15
3 1
1 56
3
3 14
2 10
以B欄為keys 作D欄(有可能空白)加總
Dim D As Object,a
Dim R As Range
Set D = CreateObject("Scripting.Dictionary")
With Sheets("基本資料")
For Each R In .Range(.Cells(2, 2), .Cells(65536, 2).End(xlUp)).Rows
D(R) = ""(如何加總???)
Next
a=d.keys
.cells(2,7)=a(0)
.cells(2,8)=加總
.cells(3,7)=a(1)
.cells(3,8)=加總
.....................
....................
End With
敬請指導作者: yangjie 時間: 2014-12-19 15:19
回復 1#yangjie
試了多遍,還是Try成功了
Dim d As Object, a, b
Set d = CreateObject("Scripting.Dictionary")
wb1.Activate
With Sheets("基本資料")
row1 = .Cells(65536, 7).End(xlUp).Row
If row1 = 1 Then Exit Sub
For i = 2 To .Cells(65536, 7).End(xlUp).Row
If .Cells(i, 7) <> "" Then
d(.Cells(i, 7).Value) = d(.Cells(i, 7).Value) + .Cells(i, 9).Value
End If
Next
End With
a = d.Keys
b = d.Items
If d.count > 0 Then
For i = 0 To d.count - 1
If CLng(a(i)) > 0 And CLng(a(i)) <= 10 Then
Controls("TextBox" & i + 1) = b(i)
End If
Next
End If