Option Explicit Function getTop10(Area As Range, IDX As Integer) As Variant Dim Score As Variant Score = Area Dim RowMax As Long RowMax = UBound(Score, 1) Dim ColumnMax As Long ColumnMax = UBound(Score, 2) Dim MaxIDX As Integer MaxIDX = IIf(RowMax > ColumnMax, RowMax, ColumnMax) Call BubbleSort(Score, MaxIDX) If (IDX <= MaxIDX) And (IDX > 0) Then If RowMax > ColumnMax Then getTop10 = Score(IDX, 1) Else getTop10 = Score(1, IDX) End If Else getTop10 = 0 End If End Function '========================================= Sub BubbleSort(DimValue As Variant, MaxIDX As Integer) Dim RowMax As Long RowMax = UBound(DimValue, 1) Dim ColumnMax As Long ColumnMax = UBound(DimValue, 2) 'バブルソート関数 Dim TmpArea As Variant Dim BaseIDX As Integer Dim CmpIDX As Integer For BaseIDX = 1 To MaxIDX - 1 For CmpIDX = BaseIDX + 1 To MaxIDX If RowMax > ColumnMax Then If DimValue(BaseIDX, 1) > DimValue(CmpIDX, 1) Then TmpArea = DimValue(BaseIDX, 1) DimValue(BaseIDX, 1) = DimValue(CmpIDX, 1) DimValue(CmpIDX, 1) = TmpArea End If Else If DimValue(1, BaseIDX) > DimValue(1, CmpIDX) Then TmpArea = DimValue(1, BaseIDX) DimValue(1, BaseIDX) = DimValue(1, CmpIDX) DimValue(1, CmpIDX) = TmpArea End If End If Next Next End Sub