PC Review


Reply
Thread Tools Rate Thread

can anyone tell me whats wrong with this line of code?

 
 
BRC
Guest
Posts: n/a
 
      5th Jan 2007
dim enddt
enddt = Range("c16").value
Range("d16").formula = "=if(" & endDt & " > " & Date & " , " & Date &
" , " & endDt & ")"

What I am getting is in cell d16 is something like
"=IF(12/15/1999 > 1/5/2007, 1/5/2007, 12/15/1999)"
which is translating (displayed) as 1/0/1900
what i was trying to get is 12/15/1999
Cell d16 is formated a date m/d/yyyy
Thanks for any advice. BRC

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Jan 2007
I would think you'd want the formula to look more like:

=if(c16>somedate,somedate,c16)

If I were writing it in the cell, I'd use:

=if(c16>today(),today(),c16)

or if I wanted a date that didn't change:

=if(c16>date(2007,1,5),date(2007,1,5),c16)

So my code would look like:

Range("d16").Formula = "=if(c16>today(),today(),c16)"

'or if I wanted a date that didn't change:

Range("d16").Formula _
= "=if(c16>date(" & Year(Date) & "," & Month(Date) & "," & Day(Date) _
& "),date(" & Year(Date) & "," & Month(Date) & "," & Day(Date) _
& "),c16)"


BRC wrote:
>
> dim enddt
> enddt = Range("c16").value
> Range("d16").formula = "=if(" & endDt & " > " & Date & " , " & Date &
> " , " & endDt & ")"
>
> What I am getting is in cell d16 is something like
> "=IF(12/15/1999 > 1/5/2007, 1/5/2007, 12/15/1999)"
> which is translating (displayed) as 1/0/1900
> what i was trying to get is 12/15/1999
> Cell d16 is formated a date m/d/yyyy
> Thanks for any advice. BRC


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      5th Jan 2007
You need to use datevalue to get the date recognised.

enddt = Range("c16").Value
Range("d16").Formula = _
"=if(datevalue(""" & enddt & _
""") > datevalue(""" & Date & """)," & _
" datevalue(""" & Date & _
"""),datevalue(""" & enddt & """))"

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"BRC" wrote:

> dim enddt
> enddt = Range("c16").value
> Range("d16").formula = "=if(" & endDt & " > " & Date & " , " & Date &
> " , " & endDt & ")"
>
> What I am getting is in cell d16 is something like
> "=IF(12/15/1999 > 1/5/2007, 1/5/2007, 12/15/1999)"
> which is translating (displayed) as 1/0/1900
> what i was trying to get is 12/15/1999
> Cell d16 is formated a date m/d/yyyy
> Thanks for any advice. BRC
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Whats wrong with this code? Angelsnecropolis Microsoft Access Form Coding 7 30th Nov 2008 06:35 AM
Whats wrong with my code? Shaka215@gmail.com Microsoft Excel Programming 4 3rd May 2007 03:47 AM
Whats wrong with this line of code? =?Utf-8?B?RWRnYXIgVGhvZW1tZXM=?= Microsoft Excel Programming 4 26th Oct 2004 12:52 PM
Whats wrong with this code? Bob Vance Microsoft Excel Worksheet Functions 1 2nd Jul 2004 04:19 AM
Whats wrong with this line? Ruslan Shlain Microsoft C# .NET 3 19th Jan 2004 08:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:26 PM.