Sub test()
Dim arr, i&, j&, m&
arr = Sheet1.[a1].CurrentRegion.Value
ReDim brr(1 To UBound(arr, 2) - 2, 1 To 5)
For j = 2 To UBound(arr, 2) - 1
m = m + 1
brr(m, 1) = arr(1, j)
For i = 2 To UBound(arr)
If brr(m, 3) = "" Then
brr(m, 2) = arr(2, 1)
brr(m, 3) = arr(2, j)
brr(m, 4) = arr(2, UBound(arr, 2) - 1)
brr(m, 5) = arr(2, UBound(arr, 2))
End If
If arr(i, j) > brr(m, 3) Then
brr(m, 2) = arr(i, 1)
brr(m, 3) = arr(i, j)
brr(m, 4) = arr(i, UBound(arr, 2) - 1)
brr(m, 5) = arr(i, UBound(arr, 2))
End If
Next
Next
Sheet1.[h4].Resize(m, 5).Value = brr
End Sub |