Sub hill() Dim maxI As Long, i As Long Dim ileZad As Integer, nrW1 As Integer, nrW2 As Integer, posZ As Integer, wPocz As Integer Dim minGl As Double, minLok As Double ' wczytanie parametrów ileZad = Cells(1, 2) maxI = Cells(1, 4) wPocz = Cells(1, 6) ' przepisanie rozwiązania początkowego For i = 3 To 2 + ileZad Cells(wPocz + i - 3, 1) = Cells(i, 5) Next i minGl = Cells(wPocz + ileZad, 5) ' właściwa pętla Randomize Application.ScreenUpdating = False For i = 1 To maxI ' losowanie nr wierszy ' nrW1 = wPocz + Int(ileZad * Rnd) nrW1 = wPocz + Int((ileZad - 1) * Rnd) Do ' nrW2 = wPocz + Int(ileZad * Rnd) nrW2 = nrW1 + 1 Loop While nrW1 = nrW2 ' zamiana zadań na pozycjach nrW1 i nrW2 posZ = Cells(nrW1, 1) Cells(nrW1, 1) = Cells(nrW2, 1) Cells(nrW2, 1) = posZ ' sprawdzenie, czy jest poprawa minLok = Cells(wPocz + ileZad, 5) If minLok < minGl Then minGl = minLok Else posZ = Cells(nrW1, 1) Cells(nrW1, 1) = Cells(nrW2, 1) Cells(nrW2, 1) = posZ End If Next i Application.ScreenUpdating = True MsgBox "Minimum globalne = " & minGl End Sub Sub zamiana_sasiadow() Dim maxI As Long, j As Long, i As Integer Dim ileZad As Integer, nrW1 As Integer, nrW2 As Integer, posZ As Integer, wPocz As Integer Dim minGl As Double, minLok As Double ' wczytanie parametrów  ileZad = Cells(1, 2) maxI = Cells(1, 4) wPocz = Cells(1, 6) ' przepisanie rozwiązania początkowego  For i = 3 To 2 + ileZad Cells(wPocz + i - 3, 1) = Cells(i, 5) Next i minGl = Cells(wPocz + ileZad, 5) ' właściwa pętla  ' Application.ScreenUpdating = False For j = 1 To maxI i = 1 Do While i < 80 nrW1 = wPocz + i - 1 nrW2 = wPocz + i ' zamiana zadań na pozycjach nrW1 i nrW2  posZ = Cells(nrW1, 1) Cells(nrW1, 1) = Cells(nrW2, 1) Cells(nrW2, 1) = posZ ' sprawdzenie, czy jest poprawa  minLok = Cells(wPocz + ileZad, 5) If minLok < minGl Then minGl = minLok Cells(166, 5) = nrW1 Cells(167, 5) = j Cells(168, 5) = minLok Else posZ = Cells(nrW1, 1) Cells(nrW1, 1) = Cells(nrW2, 1) Cells(nrW2, 1) = posZ End If i = i + 1 Loop Next j ' Application.ScreenUpdating = True MsgBox "Minimum globalne = " & minGl End Sub