I need an if statement if Cell D9 = 010000 then 000000 and if date2 has date entered then for example 09/25/05 would = 092505
I need an if statement if Cell D9 = 010000 then 000000 and if date2 has date entered then for example 09/25/05 would = 092505
I am assuming you want VBA code for the above. It appears for the first item that you are working with numbers but things might best be done with string variables. So, consider something like this:Originally Posted by Erays
alternatively:if Range("D9").Text = "010000" then Range("D9").Text = "000000"
if Cells(9,4).Text = "010000" then Cells(9,4) = "000000"
For the 2nd case, I assume that Date2 is of type Date, so you do not want to stuff numers or text into Date2. You might want to consider:
a little test program:Dim Date2 as Date Dim strDate2 as string if Date2 IsDate(Date2) = true then strDate2 = Format(Date2,"mmddyy")
Sub Test_Date2() Dim Date2 As Date Dim strDate2 As String Date2 = Cells(1, 1) If IsDate(Date2) = True Then strDate2 = Format(Date2, "mmddyy") MsgBox Date2 & vbTab & strDate2 End Sub
"It's not just the due date that's important, it's also the do date" [MWE]
When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.
Actually I need it to be aformula
OK, the first is pretty simple.Originally Posted by Erays
In, say, Cell D10, enter
The 2nd is more difficult as one needs to ensure that the data entered is a date. So, this is brute force and ugly, but it works. Assuming the "date cell" is D13, enter=IF(D9="010000","000000","something else")
into some other cell=IF(ISERROR(DATEVALUE(TEXT(D13,"dd-mmm-yyyy"))),"something else",TEXT(D13,"mmddyy"))
I am sure that others with more skill in ugly formulas will be able to improve on the 2nd forumula
"It's not just the due date that's important, it's also the do date" [MWE]
When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.
Personally, I like to take the approach such as this: HERE .. when using worksheet formulas to check for a valid Excel recognized date. As there isn't a native function that does this, you can use a VBA UDF to simulate it.
I wouldn't say MWE's method is wrong, not by any means. I, personally, try to stay away from doubling the formulas though. I would try a nested IF, something like such ...
=IF(D9="010000","000000",IF(IsADate(D10),TEXT(D10,"MMDDYY"),0))
This is assuming that your 'date2' is in D10.
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
I agree that the approach suggested (IsADate) solves the problem of no "IsDate" in Excel. I should have considered that. My attempt was to find a way around Excel's native shortcomings (and I ended up doing precisely what I suggest others do not do, i.e., incrementally build a nested mess)Originally Posted by firefytr
I did not assume that erays wanted a cascaded solution (in pcode:
but now that I reread his original post, that could be the case.if D9 = "010000" then xlcell = "000000" Elseif IsDate(D10) = true then xlcell = Format(D10,"mmddyy") end if
"It's not just the due date that's important, it's also the do date" [MWE]
When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.
I agree that some final clarification would be useful.
Erays?
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
The underlined portion has error when I put it in module
If D9 = "010000" Then xlcell = "000000" ElseIf IsDate(D10) = True Then xlcell = Format(D10,"mmddyy") End If
.. now I'm confused. Formula or VBA?Originally Posted by Erays
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
Actually I need it to be a formula but if it can be done with vba that will work just as well
This is my problem when the user puts in no date it is formated mmddyy and yeilds 010000 if he puts in date it yeilds 091605 if there is no date input i need it to read 000000 .
Thank you for all your help!
erays: well, it sounds like you were able to solve the problem and at least now it is reasonably clear what you wanted to do. I thought initially that you were playing with binary reps.Originally Posted by Erays
In the future, it will help everyone if you add a little background to the problem so those trying to assist will be better able to understand and the ping-pong of replies and clarifications can be minimized (and you get an answer much more quickly). Also, I have found that when I spend a few more minutes writing down my problem and explaining what I am trying to do, my understanding of my predicament improves and I can often solve the problem myself.
"It's not just the due date that's important, it's also the do date" [MWE]
When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.
=IF(ISERROR(DATEVALUE(TEXT(D13,"dd-mmm-yyyy"))),"000000",TEXT(D13,"mmddyy"))
Fixed my problem Thank you to all who helped