Diana Stoyka2021-01-28 11:39:46
Visual Basic
Diana Stoyka, 2021-01-28 11:39:46

8x8 0 and 1 implementation in excel?

It is necessary that in the active cell in excel with access a board is created from checks at 0 and 1.
where zero is gray / it is necessary to color it with code
. I only got the board itself and I don’t know how to do the other.
Thanks in advance for your help

Here is my code just to create an 8x8 board 0 and 1

Sub osmXosm()
For i = 1 To 8
   If i Mod 2 <> 0 Then
       For j = 1 To 8
        If j Mod 2 <> 0 Then
       Cells(j, i) = 1
          Cells(i, j) = 0
        End If
          Next j
      For k = 1 To 8
      If k Mod 2 = 0 Then
       Cells(k, i) = 1
       Cells(i, k) = 0
       End If
       Next k
     End If
Next i
End Sub

And here is how access to the active cell should look like.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Daniil Babkin, 2021-01-28

You have an 8x7 field in the example.
The code does not shine with beauty, but it works on any field size. The size is created by changing the variables lim_row and lim_col.

Sub sd()
cur_row = ActiveCell.row
cur_col = ActiveCell.Column
cur_value = 1
lim_row = 11
lim_col = 11
For i = cur_row To cur_row + lim_row
For j = cur_col To cur_col + lim_col
    If i = cur_row Then
        If cur_value = 0 Then cur_value = 1 Else cur_value = 0
    Else: If cur_value = Cells(i - 1, j).value Then If cur_value = 0 Then cur_value = 1 Else cur_value = 0
    End If
    Cells(i, j).value = cur_value
Next j
Next i
End Sub

datka, 2021-01-28

Click on the record macro (Record Macro) paint over any cell in gray. Stop macro recording (Stop Recording). See the code of the recorded macro where the cell is painted over, copy and paste below where you create 0.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question