Sub Max_Min_1_2()
Dim Darr(), Farr(), Arr(), Sarr(), i As Long, j As Long, Tmp
Darr = Range("G2", Cells(Range("G2").End(xlDown).Row, Range("XFD2").End(xlToLeft).Column)).Value
ReDim Arr(1 To UBound(Darr), 1 To 4)
For i = 1 To UBound(Darr)
ReDim Farr(0 To 36)
For j = 1 To UBound(Darr, 2)
Tmp = Darr(i, j)
If Tmp <> "" Then Farr(Tmp) = Farr(Tmp) + 1
Next j
Sarr = SortArr(Farr)
Arr(i, 1) = Sarr(UBound(Sarr)) ' lon 1
Arr(i, 2) = Sarr(UBound(Sarr) - 1) ' lon 2
Arr(i, 3) = Sarr(0) ' nho 1
Arr(i, 4) = Sarr(1) ' nho 2
Next i
Range("C2").Resize(UBound(Darr), 4) = Arr
End Sub
Private Function SortArr(ByVal Sarr As Variant)
Dim sList As Object, oList1 As Object, oList2 As Object, Arr As Variant, Tmp As String, i As Long, idx As Long
Set oList1 = CreateObject("System.Collections.arrayList")
Set oList2 = CreateObject("System.Collections.arrayList")
For i = LBound(Sarr) To UBound(Sarr)
If Sarr(i) <> "" Then
oList1.Add Sarr(i) + i / 20000
oList2.Add i
End If
Next
Set sList = oList1.Clone
sList.Sort
ReDim Arr(0 To sList.Count - 1)
For i = 0 To sList.Count - 1
idx = oList1.InDexOf(sList(i), 0)
Arr(i) = oList2(idx)
Next
SortArr = Arr
End Function