|
-
Dec 15th, 2005, 07:48 AM
#1
Thread Starter
Hyperactive Member
excel if statement with a date
I have a date in cell A1 (10/19/2005) that I am trying to write an If statement for and it keeps returning it as False when I put in the statement builder A1="10/19/2005" I only have this problem with dates, why?
-
Dec 15th, 2005, 08:12 AM
#2
Thread Starter
Hyperactive Member
Re: excel if statement with a date
I think you can't use an If statement if it's not a number value???
-
Dec 15th, 2005, 08:35 AM
#3
Re: excel if statement with a date
Does VBA support the IsDate Function?
If so, you can use that.
-
Dec 15th, 2005, 08:37 AM
#4
Frenzied Member
Re: excel if statement with a date
Post your code attempt ... that will help us to determine exactly what you are trying to do.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Dec 15th, 2005, 08:43 AM
#5
Thread Starter
Hyperactive Member
Re: excel if statement with a date
 Originally Posted by vonoventwin
when I put in the statement builder A1="10/19/2005" I only have this problem with dates, why?
didn't write code I used statement builder
-
Dec 15th, 2005, 08:49 AM
#6
Frenzied Member
Re: excel if statement with a date
I don't know about "Statement Builder", but dates work just fine in VBA code. You just have to consider that the Date/Time data type is a unique animal. It is essentially a floating point number with special handling/formatting/conversion.
Code:
'A1 10/19/05
'A2 10/22/05
'A3 10/30/05
'A4 10/31/05
'A5 11/2/05
Option Explicit
Sub Macro1()
If Cells(3, "A").Value > Cells(2, "A").Value Then
MsgBox Cells(2, "A").Value
Else
MsgBox Cells(3, "A").Value
End If
If Cells(4, "A").Value > Now() Then
MsgBox Cells(4, "A").Value
Else
MsgBox Now()
End If
End Sub
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Dec 15th, 2005, 08:53 AM
#7
Frenzied Member
Re: excel if statement with a date
A date is not a string. As I said, I don't know about "Statement Builder", but try A1 = #10/19/2005#. SQL notation for dates is like this.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Dec 15th, 2005, 10:13 AM
#8
Thread Starter
Hyperactive Member
Re: excel if statement with a date
The date is recognized as 38644 in General format, so I wrote my code as A1=38644 and it sees it as true even though the format is still as a date. Weird.. But it works!
-
Dec 15th, 2005, 10:40 AM
#9
Frenzied Member
Re: excel if statement with a date
=IF(A1=DATEVALUE("12/10/2005"),"True","False")
DATEVALUE converts the string (if possible) to a Date/Time data type. I hope this helps you. I still don't know what "Statement Builder" is or how you get into it, but it is probably just a wizard for the Formula Editor field.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Dec 15th, 2005, 10:58 AM
#10
Thread Starter
Hyperactive Member
Re: excel if statement with a date
Going off your work I did this:
VB Code:
Sub Macro1()
If Cells(2, "J").Value = "10/19/2005" Then
Cells(2, "L").Value = Cells(2, "I").Value * 0.3
MsgBox "30%"
Else
Cells(2, "L").Value = Cells(2, "I").Value
MsgBox "Not 30%"
End If
End Sub
What I want to do now is make this code work for the whole sheet. Basically:
VB Code:
If Column("J").Value = "10/19/2005" Then
Column("L").Value = Column("I").Value * 0.3
Else
Column("L").Value = Column("I").Value
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|