Anh cải tiến cái này cho chạy nhanh hơn xem thế nào:
Sub Tinh()
Dim i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer, i7 As Integer, i8 As Integer, i9 As Integer, i10 As Integer
For i1 = 1 To 10
For i2 = i1 + 1 To 10
For i3 = i2 + 1 To 10
For i4 = i3 + 1 To 10
For i5 = i4 + 1 To 10
For i6 = i5 + 1 To 10
For i7 = i6 + 1 To 10
For i8 = i7 + 1 To 10
For i9 = i8 + 1 To 10
For i10 = i9 + 1 To 10
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) + Range("B" & i6) + Range("B" & i7) + Range("B" & i8) + Range("B" & i9) + Range("B" & i10) = Range("A1") Then
MsgBox 10
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
Cells(12, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i6)
Cells(13, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i7)
Cells(14, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i8)
Cells(15, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i9)
Cells(16, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i10)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) + Range("B" & i6) + Range("B" & i7) + Range("B" & i8) + Range("B" & i9) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
Cells(12, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i6)
Cells(13, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i7)
Cells(14, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i8)
Cells(15, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i9)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) + Range("B" & i6) + Range("B" & i7) + Range("B" & i8) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
Cells(12, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i6)
Cells(13, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i7)
Cells(14, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i8)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) + Range("B" & i6) + Range("B" & i7) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
Cells(12, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i6)
Cells(13, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i7)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) + Range("B" & i6) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
Cells(12, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i6)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) + Range("B" & i5) = Range("A1") Then
MsgBox i1 & Chr(13) & i2 & Chr(13) & i3 & Chr(13) & i4 & Chr(13) & i5 & Chr(13) & i6 & Chr(13) & i7 & Chr(13) & i8 & Chr(13) & i9 & Chr(13) & i10
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
Cells(11, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i5)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3) + Range("B" & i4) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
Cells(10, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i4)
End If
Next
If Range("B" & i1) + Range("B" & i2) + Range("B" & i3 + 1) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
Cells(9, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i3)
End If
Next
If Range("B" & i1) + Range("B" & i2) = Range("A1") Then
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
Cells(8, Sheet1.Range("B7").End(xlToRight).Column) = Range("B" & i2)
End If
Next
If Range("B" & i1) = Range("A1") Then
MsgBox 1
Cells(7, Sheet1.Range("B7").End(xlToRight).Column + 1) = Range("B" & i1)
End If
Next
End Sub