Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Search dates differences

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Search dates differences

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Search dates differences

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Search dates differences

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?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Search dates differences

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?

  #7   Report Post  
Posted to microsoft.public.excel.programming
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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding differences between dates RobertK Excel Discussion (Misc queries) 6 September 18th 09 06:40 PM
Differences between Dates Jack Excel Worksheet Functions 5 July 7th 08 08:50 PM
Calculating time differences across two (or more) dates jonewer Excel Discussion (Misc queries) 1 May 11th 06 10:22 AM
Calculating differences in dates Paul Sheppard Excel Discussion (Misc queries) 5 June 30th 05 01:18 PM
Calculating differences between dates ALISONHELP Excel Worksheet Functions 2 April 6th 05 10:27 AM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"