| 
    
     |  | あー・・それは「7月でテストした後に続けて8月もテストした」場合ですね ? それは Sheet2 の B列まで含めてクリアしてなかったことが原因です。
 で、今度は他シートへの転記を止めて、表のあるシート上にテキストボックスを
 配置し、そこへ結果を表示する形にしてみました。
 
 Sub My集計2()
 Dim Mth As Long, LstR As Long, Clc As Long
 Dim MyR As Range, C As Range
 Dim MyV As String
 Const Pmt As String = _
 "集計する月を1〜12の整数で入力して下さい"
 
 With Application
 Do
 Mth = .InputBox(Pmt, Type:=1)
 If Mth = False Then Exit Sub
 Loop While Mth < 1 Or Mth > 12
 .ScreenUpdating = False
 End With
 LstR = Range("A65536").End(xlUp).Row - 1
 With Range("IV1").End(xlToLeft).Offset(, 1)
 .Value = "月"
 With .Offset(1).Resize(LstR)
 .Formula = "=MONTH($A2)"
 .Value = .Value
 End With
 If IsError(Application.Match(Mth, .EntireColumn, 0)) Then
 MsgBox "指定した月のデータはありません", 48
 .EntireColumn.ClearContents: GoTo ELine
 End If
 End With
 With Range("A1").CurrentRegion
 Clc = .Columns.Count
 .Sort Key1:=Range("IV1").End(xlToLeft), _
 Order1:=xlAscending, Key2:=Range("D1"), _
 Order2:=xlAscending, Header:=xlYes, _
 Orientation:=xlSortColumns
 .Subtotal 4, xlCount, Array(4)
 End With
 With Cells(65536, Clc).End(xlUp)
 If .Value = Mth Then
 Set MyR = Range(Cells(2, Clc), .Cells.Offset(1)) _
 .SpecialCells(4)
 Else
 Set MyR = Range(Cells(2, Clc), .Cells).SpecialCells(4)
 End If
 End With
 With ActiveSheet.TextBoxes
 If .Count = 1 Then
 .Text = ""
 ElseIf .Count = 0 Then
 .Add 0, 0, 200, 100
 End If
 End With
 MyV = "[ " & Mth & "月の集計 ]" & vbLf
 For Each C In MyR
 If C.Offset(-1).Value = Mth Then
 MyV = MyV & Cells(C.Row - 1, 4).Value & " : " & _
 Cells(C.Row, 4).Value & " 件" & vbLf
 ElseIf C.Offset(-1).Value > Mth Then
 Exit For
 End If
 Next
 MyV = Left$(MyV, Len(MyV) - 1)
 With ActiveSheet.TextBoxes(1)
 .Text = MyV
 .AutoSize = True
 .Shadow = True
 .Interior.ColorIndex = 20
 End With
 Set MyR = Nothing: Columns(Clc).ClearContents
 With Range("A1").CurrentRegion
 .RemoveSubtotal
 .Sort Key1:=Range("A1"), Order1:=xlAscending, _
 Header:=xlYes, Orientation:=xlSortColumns
 End With
 ELine:
 Application.ScreenUpdating = True
 End Sub
 
 ↓こちらは表のあるシートのシートモジュールに入れて下さい。
 
 Private Sub Worksheet_Activate()
 ActiveSheet.TextBoxes.Delete
 End Sub
 
 |  |