以下で試してみてください。
Sub Test()
Dim i As Integer
Dim buf(0 To 9) As Integer
Dim mRow As Long
Dim kRange As Range
Dim sRange As Range
With Worksheets("Sheet1")
If .Range("AL11") <> "" Then
mRow = .Cells(Rows.Count, "AL").End(xlUp).Row + 1
Else
mRow = 11
End If
For i = 0 To 9
buf(i) = WorksheetFunction.CountIf(.Range("M11:R19"), i)
If buf(i) >= 3 Then
.Cells(mRow, "AL").Offset(0, i).Value = i
.Cells(mRow, "AL").Offset(1, i).Value = buf(i)
End If
Next
Set kRange = Range(.Cells(mRow + 1, "AL"), .Cells(mRow + 1, "AU"))
Set sRange = Range(.Cells(mRow, "AL"), .Cells(mRow + 1, "AU"))
With .Sort
.SortFields.Clear
.SortFields.Add Key:=kRange, _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
.SetRange sRange
.Orientation = xlLeftToRight
.Apply
End With
.Cells(mRow + 1, "AL").Resize(1, 10).ClearContents
End With
Set kRange = Nothing
Set sRange = Nothing
End Sub
お礼
お久しぶりですkkkkkmさん。このコロナ禍にお身体は大丈夫でしょうか? バッチしできました。ありがとうございます。 このついでになんですが質問させて頂けますか?