Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Can't get the logic right

I have this code:

If ((DateValue(TB)) = Now()) And _
((DateValue(TB) + 365) <= ((Now()) + 365)) Then
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Can't get the logic right

If TB is a valid date,try this

Sub dateit()
If [TB] = Date And [TB] < Date + 365 Then MsgBox "Hi"
End Sub


--
Don Guillett
SalesAid Software

"Mr. Clean" wrote in message
om...
I have this code:

If ((DateValue(TB)) = Now()) And _
((DateValue(TB) + 365) <= ((Now()) + 365)) Then
.
.
End If


And it isn't getting me only the values of TB that are within one year
of today's date. What do I need to change to get that?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Can't get the logic right

Mr. Clean,

You don't need all those extra parenthesis.
Also, in VBA you can use "NOW" instead of "NOW()"
Also, you should convert NOW to an Integer.
If TB = 37983 and NOW = 37983.43357, your
= will never work for today's date.


The following seemed to work for me, logic wise.

Sub TestMe()
Dim TB As String
TB = "12/28/03"
If DateValue(TB) = Int(Now) And _
DateValue(TB) <= Int(Now) + 365 Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

John

"Mr. Clean" wrote in message
om...
I have this code:

If ((DateValue(TB)) = Now()) And _
((DateValue(TB) + 365) <= ((Now()) + 365)) Then
.
.
End If


And it isn't getting me only the values of TB that are within one year
of today's date. What do I need to change to get that?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Can't get the logic right

Hi John

There's an equivalent for Int(Now) called Date:

If DateValue(TB) = Date And _

Best wishes Harald
Followup to newsgroup only please

"John Wilson" skrev i melding
...
Mr. Clean,

You don't need all those extra parenthesis.
Also, in VBA you can use "NOW" instead of "NOW()"
Also, you should convert NOW to an Integer.
If TB = 37983 and NOW = 37983.43357, your
= will never work for today's date.


The following seemed to work for me, logic wise.

Sub TestMe()
Dim TB As String
TB = "12/28/03"
If DateValue(TB) = Int(Now) And _
DateValue(TB) <= Int(Now) + 365 Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

John



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Can't get the logic right

Harald,

Remembered that as soon as I saw Don's reply.
Am just so in the habit of using Int(Now) in my own
apps that I completely forgot about it.
Although both ways work, "Date" would be a better
alternative.

Thanks,
John

"Harald Staff" wrote in message
...
Hi John

There's an equivalent for Int(Now) called Date:

If DateValue(TB) = Date And _

Best wishes Harald
Followup to newsgroup only please

"John Wilson" skrev i melding
...
Mr. Clean,

You don't need all those extra parenthesis.
Also, in VBA you can use "NOW" instead of "NOW()"
Also, you should convert NOW to an Integer.
If TB = 37983 and NOW = 37983.43357, your
= will never work for today's date.


The following seemed to work for me, logic wise.

Sub TestMe()
Dim TB As String
TB = "12/28/03"
If DateValue(TB) = Int(Now) And _
DateValue(TB) <= Int(Now) + 365 Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

John







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Can't get the logic right

No criticism intended, John, and I'm not sure there's a significant gain of
speed. Just added a little info for our regular readers :-)

--
HTH. Best wishes Harald
Followup to newsgroup only please

"John Wilson" skrev i melding
...
Harald,

Remembered that as soon as I saw Don's reply.
Am just so in the habit of using Int(Now) in my own
apps that I completely forgot about it.
Although both ways work, "Date" would be a better
alternative.

Thanks,
John



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Can't get the logic right

Harald,

No criticism intended, John

I didn't take offense to your reply at all.
It's something I should have remembered (seeing as it's
not the first time that I've been reminded about it).
There probably isn't a significant gain in speed (although
some might argue that point), but if someone is only
interested in the date, it's a lot cleaner to use it as
opposed to Int(Now).

Just added a little info for our regular readers :-)

Including me...and maybe I'll remember it the next time <g

Thnaks,
John


"Harald Staff" wrote in message
...
No criticism intended, John, and I'm not sure there's a significant gain

of
speed. Just added a little info for our regular readers :-)

--
HTH. Best wishes Harald
Followup to newsgroup only please

"John Wilson" skrev i melding
...
Harald,

Remembered that as soon as I saw Don's reply.
Am just so in the habit of using Int(Now) in my own
apps that I completely forgot about it.
Although both ways work, "Date" would be a better
alternative.

Thanks,
John





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Can't get the logic right

On Sun, 28 Dec 2003 09:01:16 -0600, Mr. Clean wrote:

I have this code:

If ((DateValue(TB)) = Now()) And _
((DateValue(TB) + 365) <= ((Now()) + 365)) Then
.
.
End If


And it isn't getting me only the values of TB that are within one year
of today's date. What do I need to change to get that?



How about:

If DateValue(TB) = Date And _
(DateValue(TB) - Date) < 365 Then


--ron
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Can't get the logic right

Just to be different...adding 365 days may be an attempt to determine if
something is within 1 year. Adding 365 may not work over a leap year. This
idea is not tested to well, but just an idea...

Sub Demo()
Dim dte As Date
dte = #12/30/2004#

Select Case dte
Case Date To DateAdd("yyyy", 1, Date)
MsgBox "Within 1 year"
Case 0 To Date - 1
MsgBox "Happened in Past!"
Case Else
MsgBox "More than 1 year in the future"
End Select

End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Mr. Clean" wrote in message
om...
I have this code:

If ((DateValue(TB)) = Now()) And _
((DateValue(TB) + 365) <= ((Now()) + 365)) Then
.
.
End If


And it isn't getting me only the values of TB that are within one year
of today's date. What do I need to change to get that?



  #10   Report Post  
Posted to microsoft.public.excel.programming
COM COM is offline
external usenet poster
 
Posts: 40
Default Can't get the logic right

This discussion of 365, is something that is also not in the best interest of the "programming" community. Anyone seem to remember the whole discussion of Y2K? Some of that was because programmers did not correctly forsee or plan for things like changes in dates. You may not realize it yet, but come Feb 29th of the coming year, you may realize that 2004 is a leap year, and there are in fact 366 days. Now in some cases 365 may suffice for the intent of the program, but since March 1 of this last year, a simple sum of 365, would have lost a day...

So building on the code by John Wilson with the suggestion of Harald Staff to use Date instead of Int(Now), you can add one year (the typical result of adding 365 days) by doing the following:


Sub TestMe()
Dim TB As String
TB = "12/28/03"
If DateValue(TB) = Date And _
DateValue(TB) <= DateAdd("yyyy", 1, Date) Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

Excel/VBA will account for the 366 days. Of course you could write your own date calculating function to determine if the year is a leap year or not, but then you would have to reference the records to determine when a typically determined leap year, is not in fact a leap year. There was some discussion that 2000 was not going to be a leap year, however some time "authorities" determined that 2000 would in fact be a leap year, as it would upset the continuum *Rolling eyes* or something like that.


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
If Then Logic RPB Excel Worksheet Functions 5 July 31st 09 12:41 AM
LOGIC H0MELY Excel Discussion (Misc queries) 6 June 4th 08 10:41 PM
Logic please changetires Excel Discussion (Misc queries) 2 June 20th 06 06:21 PM
If Then logic not enough workerbeeVAB Excel Discussion (Misc queries) 4 January 5th 06 05:24 PM
IRR Logic Carrie Excel Worksheet Functions 2 November 18th 05 08:59 PM


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

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

About Us

"It's about Microsoft Excel"