Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function check(number As Integer) As Boolean
- If number Mod 2 = 0 Then
- cheñk = False
- Else
- cheñk = True
- End If
- End Function
- Sub Êíîïêà1_Ùåë÷îê()
- Dim N As Byte, i As Byte, m As Byte
- Dim num As Integer
- Dim n_spir As Integer
- Dim r As Range
- Cells.ClearContents
- Cells.Borders.LineStyle = xlNone
- Cells.Interior.Color = vbWhite
- Set r = Range("A4")
- num = 1
- N = Val(InputBox("Ââåäèòå ÷èñëî n:", , 7))
- If N = 0 Then Exit Sub
- ReDim a(1 To N, 1 To N) As Integer
- For n_spir = 0 To N \ 2 - 1
- m = N - 1 - 2 * n_spir
- For i = 1 To m
- a(n_spir + 1, i + n_spir) = num: num = num + 1 '??????
- Next i
- For i = 1 To m
- a(i + n_spir, N - n_spir) = num: num = num + 1 '????
- Next i
- For i = 1 To m
- a(N - n_spir, N - n_spir - i + 1) = num: num = num + 1 '?????
- Next i
- For i = 1 To m
- a(N - n_spir - i + 1, n_spir + 1) = num: num = num + 1 '?????
- Next i
- Next n_spir
- If N Mod 2 = 1 Then a(N \ 2 + 1, N \ 2 + 1) = N ^ 2
- r.Resize(N, N) = a: Alg r, N
- End Sub
- Sub Alg(r As Range, N As Byte)
- Dim i As Byte, n_spir As Byte
- If N Mod 2 = 0 Then n_spir = N \ 2 Else n_spir = N \ 2 + 1
- For i = 0 To n_spir - 1
- With r.Offset(i, i).Resize(N - 2 * i, N - 2 * i)
- .Borders(xlEdgeLeft).Weight = xlMedium
- .Borders(xlEdgeTop).Weight = xlMedium
- .Borders(xlEdgeBottom).Weight = xlMedium
- .Borders(xlEdgeRight).Weight = xlMedium
- End With
- With r.Offset(i, i)
- .Borders(xlEdgeBottom).Weight = xlMedium
- If i >= 1 Then .Borders(xlEdgeLeft).LineStyle = xlNone
- End With
- For Each r In Range("A4:G11")
- If check(r.Value) = False Then
- r.Interior.Color = vbBlue
- End If
- Next
- Next i
- End Sub
Add Comment
Please, Sign In to add comment