You are redim'ing your arrays inside a loop which reinitializes, then dropping any data inside the array. Use the PRESERVE keyword to insure you don't dump your array when redimensioning it ReDim Preserve atoms(0 To 20, 0 To 20)
Redimensioning your arrays to the exact same size makes no sense. They are already 0 To 20, 0 To 20 because you already set that. Redim them once outside of your for loops and then leave them alone.
Insure that your atoms and atomschange arrays are declared properly at the top of your code. It's complaining (probably when you redim them) that those two variables aren't arrays.
You know the size of the arrays before this code executes, so declare them and dim them properly in the declaration, then just use them (removing the superfluous and incorrect use of redim in your loop:
Sub somesumroutine()
Dim atoms(0 to 20, 0 to 20) as Integer
Dim atomschange(0 to 20, 0 to 20) as Integer
For j = 0 To 20
For i = 0 To 20
atomschange(j, i) = 0
If i Mod 2 = 0 And j Mod 2 = 0 Then
[B2].Offset(j, i).Interior.ColorIndex = 37
atoms(j, i) = 1
Else
[B2].Offset(j, i).Interior.ColorIndex = 36
atoms(j, i) = 0
End If
Next i
Next j
End Sub
Consider using UBound and LBound of your atoms array to set the loops so you don't have to use the 0 to 20 over and over again. This way you can dim your arrays once and leave the rest of your code alone:
Sub somesumroutine()
Dim atoms(0 to 20, 0 to 20) as Integer
Dim atomschange(0 to 20, 0 to 20) as Integer
For j = lBound(atoms, 1) To uBound(atoms, 1)
For i = lBound(atoms, 2) To uBound(atoms, 2)
atomschange(j, i) = 0
If i Mod 2 = 0 And j Mod 2 = 0 Then
[B2].Offset(j, i).Interior.ColorIndex = 37
atoms(j, i) = 1
Else
[B2].Offset(j, i).Interior.ColorIndex = 36
atoms(j, i) = 0
End If
Next i
Next j
End Sub
Debugand share which line is highlighted. That is the line to focus on.