Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ezhov-da/96b6c9da8c808b129251171f698d0092 to your computer and use it in GitHub Desktop.
Save ezhov-da/96b6c9da8c808b129251171f698d0092 to your computer and use it in GitHub Desktop.
vba разукрашивание ячеек рандомным цветом.vba
Sub startPaintExcel()
Cells.Delete Shift:=xlUp
Columns.ColumnWidth = 0.6
Rows.RowHeight = 5.8
Dim rowMax As Integer: rowMax = 1000
Dim columnMax As Integer: columnMax = 1000
For r = 1 To rowMax
For c = 1 To columnMax
If (r Mod 2 = 0) And (c Mod 2 = 0) Then
Cells(r, c).Interior.ColorIndex = getRandomNumber()
End If
If (r Mod 2 <> 0) And (c Mod 2 <> 0) Then
Cells(r, c).Interior.ColorIndex = getRandomNumber()
End If
Next c
Next r
End Sub
Private Function getRandomNumber() As Integer
getRandomNumber = Int((56 - 1 + 1) * Rnd + 1)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment