Making a simple toroidal 14x14 chess board in Excel, placing multiple copies beside and below each other so it's easier to see how pieces move around the edge of the board. Need all boards to update when a piece is moved, i.e. value is changed, which apparently requires VBA.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row <= 42 And Target.Column <= 42 Then
Dim i As Integer, j As Integer, x As Integer, y As Integer
Dim z As String
x = Target.Row Mod 14
y = Target.Column Mod 14
z = Target.Value
For i = 0 To 2
For j = 0 To 2
Dim m As Integer, n As Integer
m = i * 14 + x
n = j * 14 + y
MsgBox (i & "-" & j & "-" & m & "-" & n & "-" & z)
Cells(m, n).Value = z
Next j
Next i
End If
End Sub
(The MsgBox line is just test code.)
The line "Cells(m, n).Value = z" is the problem. Without it, the code works fine and the loop exits. When I put it in, it does what I want, fills in the correct cells with the changed value, but then the loop doesn't exit and gets really weird. I realize this is probably a very simple error, but I've been all over here and tutorial sites over the last five hours and have found nothing.