ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba for Today() (https://www.excelbanter.com/excel-programming/426544-vba-today.html)

tkraju via OfficeKB.com

vba for Today()
 
I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.

--
Message posted via http://www.officekb.com


Jacob Skaria

vba for Today()
 
Use Date()

If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")= Date()

If this post helps click Yes
---------------
Jacob Skaria


"tkraju via OfficeKB.com" wrote:

I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.

--
Message posted via http://www.officekb.com



joel

vba for Today()
 
I see two problems with your posting

1) the dfgference between now() and today is now includes hours and minutes
while today(0 is set at midnight of the date. Time is a number with days the
whole part of the number and hours and minutes are the fractional part.
April, 7, 2009 = 39910. 8 AM is 8hours/24 hours = .3333333

So today() = 39910 and Now() = 39910.3333333333

Using the INT function will make them equivalent

Today() = Int(Now())


2) A text box returns TEXT not a Date. You need to use the
DATEVALUE("4/1/09") function to convert the text string to a number.
DateValue will take any format string the excel recognizes "4/1/09",
"4/1/2009", "April 1, 2009"). the only problem with datevalue is the
internation standards wherre US has month 1st and England uses Day 1st.

from:
If Cells(j,"A")=Me.TextBox1.Text
to:
If Cells(j,"A")=DateValue(Me.TextBox1.Text)

"tkraju via OfficeKB.com" wrote:

I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.

--
Message posted via http://www.officekb.com



Jacob Skaria

vba for Today()
 
If Format(Range("A1"),"dd-mm-yyyy")=format(Date(),"dd-mm-yyyy")

If this post helps click Yes
---------------
Jacob Skaria


"tkraju via OfficeKB.com" wrote:

I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.

--
Message posted via http://www.officekb.com



TUNGANA KURMA RAJU

vba for Today()
 
Thank you joel,
I Learned new thing.I used Cells(j,"B")=Int(Now) ,it gave me desired results.
thank you once again.

"joel" wrote:

I see two problems with your posting

1) the dfgference between now() and today is now includes hours and minutes
while today(0 is set at midnight of the date. Time is a number with days the
whole part of the number and hours and minutes are the fractional part.
April, 7, 2009 = 39910. 8 AM is 8hours/24 hours = .3333333

So today() = 39910 and Now() = 39910.3333333333

Using the INT function will make them equivalent

Today() = Int(Now())


2) A text box returns TEXT not a Date. You need to use the
DATEVALUE("4/1/09") function to convert the text string to a number.
DateValue will take any format string the excel recognizes "4/1/09",
"4/1/2009", "April 1, 2009"). the only problem with datevalue is the
internation standards wherre US has month 1st and England uses Day 1st.

from:
If Cells(j,"A")=Me.TextBox1.Text
to:
If Cells(j,"A")=DateValue(Me.TextBox1.Text)

"tkraju via OfficeKB.com" wrote:

I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.

--
Message posted via http://www.officekb.com



tkraju via OfficeKB.com

vba for Today()
 
Thank you Joel,
I learned a new thing,I used Cells(j,"B")=Int(Now) ,it gave me desired
results.
Thanks once again.
joel wrote:
I see two problems with your posting

1) the dfgference between now() and today is now includes hours and minutes
while today(0 is set at midnight of the date. Time is a number with days the
whole part of the number and hours and minutes are the fractional part.
April, 7, 2009 = 39910. 8 AM is 8hours/24 hours = .3333333

So today() = 39910 and Now() = 39910.3333333333

Using the INT function will make them equivalent

Today() = Int(Now())

2) A text box returns TEXT not a Date. You need to use the
DATEVALUE("4/1/09") function to convert the text string to a number.
DateValue will take any format string the excel recognizes "4/1/09",
"4/1/2009", "April 1, 2009"). the only problem with datevalue is the
internation standards wherre US has month 1st and England uses Day 1st.

from:
If Cells(j,"A")=Me.TextBox1.Text
to:
If Cells(j,"A")=DateValue(Me.TextBox1.Text)

I have w/sheet cell B1= Now(),i.e date with time.
what vba code should I use whether B1=today's date or not.
I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
its not giving me desired results.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200904/1



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com