VBA problem: if date is less than other date then do!

totalnatal

New Member
Joined
Jun 9, 2010
Messages
33
Hi,

I have the following lines of code:
Code:
 If r < Range("a3").Offset(i, 17).Value Then
            Range(Range("a3").Offset(s, 4), Range("a3").Offset(s, 9)).Value = 0

where r = Range("a3").Offset(i, 0).Value

Both r and Range("a3").Offset(i, 17).Value correspond ot cells which have a date in it. The date in r is calculated by vba whereas the one in the offset is calculated via formula.

As you can see, I'm trying to do something like: If r is less than the offset cell value (i.e 15/06/2007 < 24.04.2007) then do a set of commands.

for some reason everytime I run the macro, it does not to the comparison properly as the set of commands still gets executed even if R is not less than the offset cell value.

Can you help me ?

Thank you
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
At first it was defined as Long. Then just tried by defining r as Date and it is still not working. The offset cell's format is Date aswell.

I dunno what to do....
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top