Option Explicit
Sub TimSoThieu()
Dim Rng As Range, Cls As Range: Dim Color_ As Byte
Dim Max_ As Long, jJ As Long, Rws As Long, Ww As Long, Ff As Long
Set Rng = Application.InputBox("Hay Chon Các O:", Type:=8)
Color_ = Rng.Interior.ColorIndex + 1
If Color_ < 34 Or Color_ > 42 Then Color_ = 35
Set Cls = Cells(Rng.Cells(1).Row + 1, 1)
jJ = Rng.Cells.Count
Cls.Resize(300 * jJ).EntireRow.ClearContents
Rws = Cls.Row + 1
For jJ = 0 To 9
With Application.WorksheetFunction
If .CountIf(Rng, jJ) = 0 Then
Cells(Rws, "iV").End(xlToLeft).Offset(, 1).Value = jJ
End If
End With
Next jJ
Rng.Interior.ColorIndex = Color_
Set Rng = Cells(Rws, "B").CurrentRegion
Max_ = Cells(Rng.Row, "iV").End(xlToLeft).Column
For Ff = 2 To Max_
For Ww = 2 To Max_
If Ww <> Ff Then
For jJ = 2 To Max_
Cells(Rws + jJ, "iV").End(xlToLeft).Offset(, 1).Value = _
100 * Cells(Rws, Ff).Value + 10 * Cells(Rws, Ww).Value _
+ Cells(Rws, jJ).Value
Next jJ
End If
Next Ww
Next Ff
End Sub