|
▼ふくじ さん:
こんばんは。
>合計、データ数の計算がわからず悩んでいます。
Dictionaryをもうひとつ追加して、
dic は合計用、
dic2 は データ数用
としたら、どうですか?
Sub Try1()
Dim rng As Range
Dim v
Dim ss As String
Dim i As Long, j As Long
Dim dic As Object
Dim dic2 As Object
With Worksheets(1)
v = .Range("A2", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4).Value
End With
Set dic = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
dic("品名") = "合計"
dic2("品名") = "データ数"
For i = 1 To UBound(v)
ss = v(i, 1)
For j = 2 To 4
If IsEmpty(v(i, j)) Then Exit For
dic(ss) = dic(ss) + v(i, j)
dic2(ss) = dic2(ss) + 1
Next
Next
'集計結果を新しいシートに書き出す
Worksheets(2).Range("A1").Resize(dic.Count, 3).Value = _
Application.Transpose(Array(dic.Keys, dic.Items, dic2.Items))
Set dic = Nothing
Set dic2 = Nothing
End Sub
|
|