ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   If Then Statement Clarification (https://www.excelbanter.com/excel-discussion-misc-queries/68306-if-then-statement-clarification.html)

Joanne

If Then Statement Clarification
 
This is an example of what I am trying to do

Cell A1 1/1/04
A2 12/31/04
A3 1/1/07

If A2-A1 = 1460
A3-A2 = 731
Since A2-A1 is greater than A3-A2 I want to take the difference from
1460-731 (729) and add that to 1/1/04 to make a new date of 12/31/02 but if
the difference between A2-A1 and A3-A2 is negative, I want to return A3 as
the date.
Thanks


Ian G

If Then Statement Clarification
 
Try this code

Sub Dates()
firstdates = Range("a2") - Range("a1")
seconddates = Range("a3") - Range("a2")
If seconddates firstdates Then
MsgBox Range("a3")
Else
MsgBox Range("a1") + firstdates - seconddates
End If
End Sub

Ian G


Ian G

If Then Statement Clarification
 
If you want a formula to do the same, try
=IF((2*A2-A1-A3)<0,A3,(2*A2-A3))

Ian G


Joanne

If Then Statement Clarification
 
Thank you Ian!

"Ian G" wrote:

If you want a formula to do the same, try
=IF((2*A2-A1-A3)<0,A3,(2*A2-A3))

Ian G




All times are GMT +1. The time now is 11:37 PM.

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