Help: Comparing two values

  • Thread starter Thread starter woknick
  • Start date Start date
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top