1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Sub TestRech()
Dim Haz As New Collection
Dim Z As Long
Dim k As Long
Dim i As Long
Dim j As Integer
Dim A As Integer, B As Integer, C As Integer, D As Integer
Dim L(3) As String
Dim WS2 As Worksheet
Dim WS3 As Worksheet
Set WS2 = ThisWorkbook.Worksheets("Feuille2")
Set WS3 = ThisWorkbook.Worksheets("Feuille3")
D = WS2.Cells(14, 13)
1
Do
Randomize
k = Int(Rnd * 1000 + 1)
On Error Resume Next
Haz.Add k, CStr(k)
On Error GoTo 0
Loop Until Haz.Count = 100
For i = 1 To 100
For j = 1 To 10
WS3.Cells(Haz(i), j) = WS2.Cells(Haz(i), j)
Next j
Next i
With WS3
For i = 1 To 10
A = WorksheetFunction.CountIf(.Cells(1, i).Resize(1000), "A")
If A < WS2.Cells(1 + i, 13) + D And A > WS2.Cells(1 + i, 13) - D Then
B = WorksheetFunction.CountIf(.Cells(1, i).Resize(1000), "B")
If B < WS2.Cells(1 + i, 14) + D And B > WS2.Cells(1 + i, 14) - D Then
C = WorksheetFunction.CountIf(.Cells(1, i).Resize(1000), "C")
If C < WS2.Cells(1 + i, 15) + D And C > WS2.Cells(1 + i, 15) - D Then
If i = 10 Then
MsgBox "Solution"
For j = 1 To 100
WS2.Cells(j, 17) = Haz(j)
Next j
Exit Sub
End If
Else
Exit For
End If
Else
Exit For
End If
Else
Exit For
End If
Next i
.Cells.ClearContents
End With
Set Haz = New Collection
GoTo 1
End Sub |
Partager