I'm actually quite surprised that I'm having so much trouble finding as answer for this. I have 2 columns containing a bunch of numbers (on the same worksheet). I simply want to have code to say "If the value in column 1 > the value in column 2, do this" for each row in the columns. I tried
If sheet.range("B2:B35").Value > sheet.range("C2:C35").Value Then
'do something
End If
But apparently it doesn't work that way.
You need to think about a loop to check each row independently of the others.
The idea is something like:
The
Value
can be omitted as it is implicit, meaningSheet.Range("B" & i).Value
returns an identical result asSheet.Range("B" & i)
Additionally, there are numerous ways to address a cell depending on your needs.
And either of the above methods can be used in conjunction with
Offset()
if you are looking to move around a given worksheet such as:I personally tend to use
Cells(2, i)
in these cases, but I just usedRange
as I borrowed it straight from your example code snippet.