|
これでどうでしょーか ?
Sub MyData_Count()
Dim Sd As Date, Fd As Date
Dim FR As Range, FR2 As Range
Dim MyR As Range, C As Range
Dim Dic As Object
Dim MyKey As Variant, MyItem As Variant
Dim i As Long
With Application
Sd = .InputBox("取得開始の年月日を入力して下さい", Type:=1)
Fd = .InputBox("取得終了の年月日を入力して下さい", Type:=1)
End With
If Sd = False Or Fd = False Then Exit Sub
With Range("C:C")
Set FR = .Find(Sd, , xlFormulas, xlWhole)
Set FR2 = .Find(Fd, , xlFormulas, xlWhole, , xlPrevious)
End With
If FR Is Nothing Or FR2 Is Nothing Then
MsgBox "入力された日付は見つかりません", 48
Exit Sub
End If
Set Dic = CreateObject("Scripting.Dictionary")
Set MyR = Range(FR, FR2).Offset(, -1)
For Each C In Range(FR, FR2).Offset(, -1)
If Dic.Exists(C.Value) = False Then
Dic.Add C.Value, WorksheetFunction.CountIf(MyR, C.Value)
End If
Next
MyKey = Dic.Keys: MyItem = Dic.Items
For i = 0 To Dic.Count - 1
Debug.Print MyKey(i) & " : " & MyItem(i) & "件"
Next i
Set FR = Nothing: Set FR2 = Nothing
Set MyR = Nothing: Set Dic = Nothing
Erase MyKey, MyItem
With Application.VBE.MainWindow
.Visible = True
.SetFocus
End With
SendKeys "^(g)"
End Sub
*Excelのバージョンによっては、VBEを操作するコードが使えないケースが
あるかも知れません。そのときは With Application.VBE.MainWindow 以下
を削除し、手作業でイミディエイトウィンドウを開いて下さい。
|
|