if statements vs date ranges

U

underhill

Hi again!

Is it possible to do this in excel

dim date1 datee etc as date

date = Format(Range("b5").Value, "dd/mm/yyyy") (b5 is a date cell i
dd/mm/yyyy format - excel pushes the value into mm/dd/yyyy otherwise)

date2 = Format(#10/1/2004#, "dd/mm/yyyy")
date3 etc etc

if date > date2 AND date < date3 then
code
elseif date > date4 AND date < date4 then
code
else
code
endif


Its really the AND operator that I am having trouble with. I tried
case statement but that didnt work either.

Sorry to clog up the user group with basic questions but I have bee
out of the game for a little while

:) :
 
B

Bob Phillips

You cannot use date as a variable, as this is a built-in referring to today.

Also, format will look to return a string not a date. Try something like

dim date1 datee etc as date

date1 = CDate(Range("b5").Value
date2 = CDate("2004/10/1")

if date > date2 AND date < date3 then
code
elseif date > date4 AND date < date4 then
code
else
code
endif

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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

Top