Bug in Sheets: If statement with "<" operator
Hello, last weekend I was fighting against a very ugly bug. It happens in a procedure like this
- private sub ChangeColor()
- dim x as variant
- dim iLimit as integer
-
- iLimit = range("Player").value
- for each x in range("User")
- x.Select
- (1) if iLimit > x.value and not isempty(x) then
- (2) if x.value < iLimit and not isempty(x) then
- Selection.Interior.Color = 49407
- else
- Selection.Interior.Color = RGB(255,255,255)
- end if
- next x
- end sub
When I use (1) it works correctly, if I use (2) I get following error message when I press run:
- Encountered "1" at line 73, column 31.Was expecting one of:
- <NL>, ":", "&", <DOT>, "^", "(", "-", "+", "=", ">", "<", ">=", "<=", "<>", "\\", "/", "*", "IS", "LIKE", "MOD", "AND", "OR", "XOR", "EQV", "IMP",
The strange thing is, and this makes this bug so ugly, line 73 is in a total different area of the code about 40 lines below. This code is in line 73:
- iActualRow = iActualRow + 1
For whatever reason the compiler doesn't recognize the "+" between "iActualRow" and "1". Changing the above code back to (1) solves all issues.