Losowanie i kolorowanie pól

Losowanie i kolorowanie pól

Program: losujący pola (wartość od 0 do 1), a następnie kolorujący.

Gdy:

  • na zielono gdy wartość jest mniejsza od 0.5,
  • na czerwono w przeciwnym wypadku.

Kompilator: Microsoft Excel

Galeria:

Program w akcji.

Kod programu:

Sub makro_1()

For i = 1 To 100
    For j = 1 To 100
        Cells(i, j) = Rnd
    Next j
Next i

For i = 1 To 100
    For j = 1 To 100
        If Cells(i, j) > 0.5 Then
            Cells(i, j).Select
            With Selection.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 255
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
        Else
            Cells(i, j).Select
            With Selection.Interior
                .Pattern = xlSolid
                .PatternColorIndex = xlAutomatic
                .Color = 5287936
                .TintAndShade = 0
                .PatternTintAndShade = 0
            End With
        End If
    Next j
Next i

End Sub