Bonjour à tous,

Nouvelle sur ce site, je demande votre aide. J'espère que qqn verra mon message.
Je suis étudiante, je dois réaliser sur VBA le jeu Conways's game of life. Vous voyez ce que j'ai fait ci-dessous.
Les procédures fonctionnent sauf l'avant dernière celle Sub adjacent_cells().
En utilisant la touche F8 pour voir où cela bloque j'ai trouvé que le problème était à partir de la ligne "For Each cell In Range(Cells(1, 1).CurrentRegion)"
J'ai l'érreur code 91 "object required"

Voici l'énoncé du jeux:
Write a macro that implements Conway's Game of Life in VBA. The game is to be played over a 30*50 grid for 100 iterations. All cells in the range will contain no values and be either black or white at the beginning of the game.
The rules to the game are simple: it is a zero-player game; that is, no human intervention is involved. Cells are said to be alive (colored in black) or dead (colored in white). The rules are as follow:
- An alive cell dies of loneliness if it is surrounded by* 0 or 1 cells.
- An alive cell dies of overcrowding if it is surrounded by 4 or more cells.
- An alive cell stays alive if it is surrounded by 2 or 3 cells.
- A dead cell becomes alive if it is surrounded by 3 cells.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Sub creation_of_the_game()
'formatage des cellules pour des carrés de 1cm de côté
Columns("A:AX").ColumnWidth = 5.35
Rows("1:30").RowHeight = 28.35
End Sub
 
Sub numbers_in_cells()
'Ici nous écrivons 1 en noir dans les cellules noires, et 0 en blanc dans les cellules blanches
Dim cell_colored As Range
For Each cell_colored In Range(Cells(1, 1), Cells(30, 50))
If cell_colored.Interior.Color = RGB(0, 0, 0) Then
cell_colored = 1
cell_colored.Font.Color = RGB(0, 0, 0)
 
Else: cell_colored = 0
cell_colored.Font.Color = RGB(255, 255, 255)
End If
Next cell_colored
End Sub
 
Sub adjacent_cells_test()
'Le but est de compter la valeur des carrés adjacents à la cellule sélectionnée
'Essayons avec la cellule C4 et affichons le résultat pour voir si cela fonctionne
Dim cell_selected As Integer
cell_selected = Range("C4") + Range("C4").Offset(1, 0) + Range("C4").Offset(0, 1) + Range("C4").Offset(-1, 0) + Range("C4").Offset(0, -1) + Range("C4").Offset(-1, -1) + Range("C4").Offset(-1, 1) + Range("C4").Offset(1, -1) + Range("C4").Offset(1, 1)
MsgBox (cell_selected)
End Sub
 
Sub adjacent_cells()
'Etendons la méthode à tout le jeu
Dim cell As Range
Dim number_of_black_around As Integer
Dim iteration As Integer
 
iteration = 1
While iteration < 101
 
number_of_black_around = cell + cell.Offset(1, 0) + cell.Offset(0, 1) + cell.Offset(-1, 0) + cell.Offset(0, -1) + cell.Offset(-1, -1) + cell.Offset(-1, 1) + cell.Offset(1, -1) + cell.Offset(1, 1)
 
For Each cell In Range(Cells(1, 1).CurrentRegion)
 
If cell.Interior.Color = RGB(0, 0, 0) Then
If number_of_black_around = 0 Or number_of_black_around = 1 Or number_of_black_around = 4 Then
cell.Interior.Color = RGB(255, 255, 255)
ElseIf number_of_black_around = 2 Or number_of_black_around = 3 Then
cell.Interior.Color = RGB(0, 0, 0)
End If
 
ElseIf cell.Interior.Color = RGB(255, 255, 255) Then
If number_of_black_around = 3 Then
cell.Interior.Color = RGB(0, 0, 0)
Else: cell.Interior.Color = RGB(255, 255, 255)
End If
End If
 
Next cell
 
iteration = iteration + 1
Wend
End Sub
 
Sub button_start()
'Le code suivant permet de lancer le jeu depuis Excel avec le bouton "Start Playing"
'Il exécute les procédures les unes après les autres
creation_of_the_game
numbers_in_cells
adjacent_cells
End Sub
MERCI BEAUCOUP!!