If Then Statement Clarification

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

max value 1
Vlookup with If condition 1
time formulas 2
date range 11
Conditional Printing 2
Combining Text From Cells 3
Return latest value from data range 4
Need () around whole Numbers 6

Back
Top