View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
mac_see[_3_] mac_see[_3_] is offline
external usenet poster
 
Posts: 16
Default Search dates differences

It works but it will stop at BB10. if I have dates in more rows lets say
AV2:BB750, the code would be very long. I don't know VBA but can you use
something like xlDown so that irrespective of the date range, it will still
give you result and the code will be short?

"David" wrote:

Hi Mac,
Try this and see if it does what you want:
Sub Macro2()
Range("AV2").Select
For I = 1 To 9
ThisRow = ActiveCell.Row
V0 = ActiveCell.Value
V1 = ActiveCell.Offset(0, 1).Value
V2 = ActiveCell.Offset(0, 2).Value
V3 = ActiveCell.Offset(0, 3).Value
V4 = ActiveCell.Offset(0, 4).Value
V5 = ActiveCell.Offset(0, 5).Value
V6 = ActiveCell.Offset(0, 6).Value
Val1 = V1 - V0
Val2 = V2 - V1
Val3 = V3 - V2
Val4 = V4 - V3
Val5 = V5 - V4
Val6 = V6 - V5
SaveVal = Val1
If Val2 Val1 Then SaveVal = Val2
If Val3 SaveVal Then SaveVal = Val3
If Val4 SaveVal Then SaveVal = Val4
If Val5 SaveVal Then SaveVal = Val5
If Val6 SaveVal Then SaveVal = Val6
Range("AS" & ThisRow).Value = SaveVal
Range("AT" & ThisRow).Value = Val6
ActiveCell.Offset(1, 0).Select
Next I
End Sub

Thanks,

"mac_see" wrote:

The random dates are in the range AV2:IV10 and not AV2:BB10

"mac_see" wrote:

I have nothing in range AS2:AS10
I have some random dates in range AV2:BB:10

What I want to do is, check the difference between the two dates AW2-AV2 and
keep it in memory, then check difference of AX2-AW2, keep it in memory... do
this till BB2-BA2 and whichever number is highest in the memory, put in it
cell AS2. Continue the same thing till row 10.

Also whatever is the difference of the last dates (BB2-BA1), put it in cell
AT2..... do this till row 10.

Maxi