Help: Comparing two values

W

woknick

I have 2 numbers that I want to compare to each other.
The first number is in B4 and the second is in C4. The comparison wil
be

if C4 < B4 Then
'Do something

how can I create a loop to perform this check on rows B4 through B2
and C4 through C24. so that each row will be compared.

thanks in advanc
 
N

Norman Jones

Hi Woknick,

Try:

Sub test02()
Dim cell As Range

For Each cell In Range("C4:C24")
If cell.Value > cell.Offset(0, 1) Then
'Do something
End If
Next

End Sub
 
F

Frank Kabel

Hi
one way:

sub foo()
dim i as integer
for i = 4 to 24
with cells(i,2)
if .value>.offset(0,1).value then
'do something
end if
end with
next
end sub
 
S

Soo Cheon Jheong

Hi,

Option Explicit
Sub TEST()

Dim CL As Range
Dim i As Long

For Each CL In Range("B4:B24")
i = i + 1
If CL(i) > CL(i, 2) Then

'Do something

End If
Next

End Sub



--
Regards,
Soo Cheon Jheong
_ _
^ ^
V
 
Top