Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
BRC BRC is offline
external usenet poster
 
Posts: 10
Default can anyone tell me whats wrong with this line of code?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default can anyone tell me whats wrong with this line of code?

I would think you'd want the formula to look more like:

=if(c16somedate,somedate,c16)

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

=if(c16today(),today(),c16)

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

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

So my code would look like:

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

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

Range("d16").Formula _
= "=if(c16date(" & 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default can anyone tell me whats wrong with this line of code?

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Whats wrong with this code? Steve[_73_] Excel Programming 2 January 31st 06 04:13 PM
Whats wrong with this code? Joseph[_54_] Excel Programming 2 November 26th 04 04:31 PM
Whats wrong with this line of code? Edgar Thoemmes[_4_] Excel Programming 4 October 26th 04 12:52 PM
whats wrong with this code LiSa Excel Programming 2 September 8th 04 05:47 PM
Whats wrong with this code gav meredith Excel Programming 5 April 21st 04 12:01 AM


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"