View Single Post
  #7   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 does work for unlimited rows but not for columns. If I have dates till the
end of the sheet (column IV), it does not give the correct result.

I think there is a lot of confusion in this thread. I am starting a new
thread for this issue with a clear explaination.

Thanx
Maxi

"David" wrote:

Sub Macro2()
Range("AV2").Select
Do Until ActiveCell.Value = ""
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
Loop
End Sub
If the dates are elsewhere, then the relationships of the dates must be
spelled out. This will work for what you have shown.

"mac_see" wrote:

Dates can also be in more columns. Lets say AV2:IV1056

The code should work irrespective of the rows and columns.

Maxi

"mac_see" wrote:

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?