I want to let Excel automatically change the color of a cell if that cell's value is either larger or smaller by 10% than the cell that at same row but three columns to the left.
Here is the code:
Sub testing1()
Dim x As Integer
Dim y As Integer
For x = 35 To 5 Step -3
For y = 11 To 75 Step 1
If Cells(y, x).Value < 0.9 * Cells(y, x - 3).Value Or _
Cells(y, x).Value > 1.1 * Cells(y, x - 3) Then
Cells(y, x).Interior.ColorIndex = 22
End If
Next y
Next x
End Sub
Before I defined y, I used a single row, like 11. It is like this: cells(11,x).value; the code ran without problems.
However, when I change from numbers to variable y, I get an error: Error 13, type mismatch.
What is the source of this error?