Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA calculate avg dates

In column A I have the Customer Number, Column B = Item Number, Column
J = Dates. I am trying to find a quick way to calculate the average
days between orders for the same item for the same customer. I was
trying to put it into a formula and then paste into teh right cells.
This takes a very long time.

Thanks,
Jay

Sub AvgThisItem()
Application.ScreenUpdating = False
Dim Rng As Range
Dim i
Dim Lstrow As Long
Dim Fn As String

Lstrow = Range("A6").End(xlDown).Row
Set Rng = Range("B6", Range("B6").End(xlDown))

Range("K5") = "Days"
Range("L5") = "Avg Days"
Range("N1") = "=sumproduct(($B$6:$b$" & Lstrow & "=$B1)*($A$6:$a$" & _
Lstrow & "=$A1)*(1))"
Range("O1") = "=sumproduct(($B$6:$b$" & Lstrow & "=$B1)*($A$6:$a$" & _
Lstrow & "=$A1)*($K$6:$k$" & Lstrow & "))"
Range("K1") = "=ABS(IF(B1=B2,J1-J2,0))"
Range("K1:O1").Copy
Range("K6:K" & Lstrow).PasteSpecial xlPasteFormulas
For Each i In Rng
If i < i.Offset(-1, 0) Then
Range("L" & i.Row).Value = "=O" & i.Row & "/n" & i.Row
Else
End If
Next i
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 120
Default VBA calculate avg dates

Jay,
Arrange your data all by colums A, B and J (here in ascending order) first.
You will get another view right away.
--
Regards
Petr Bezucha


"jlclyde" wrote:

In column A I have the Customer Number, Column B = Item Number, Column
J = Dates. I am trying to find a quick way to calculate the average
days between orders for the same item for the same customer. I was
trying to put it into a formula and then paste into teh right cells.
This takes a very long time.

Thanks,
Jay

Sub AvgThisItem()
Application.ScreenUpdating = False
Dim Rng As Range
Dim i
Dim Lstrow As Long
Dim Fn As String

Lstrow = Range("A6").End(xlDown).Row
Set Rng = Range("B6", Range("B6").End(xlDown))

Range("K5") = "Days"
Range("L5") = "Avg Days"
Range("N1") = "=sumproduct(($B$6:$b$" & Lstrow & "=$B1)*($A$6:$a$" & _
Lstrow & "=$A1)*(1))"
Range("O1") = "=sumproduct(($B$6:$b$" & Lstrow & "=$B1)*($A$6:$a$" & _
Lstrow & "=$A1)*($K$6:$k$" & Lstrow & "))"
Range("K1") = "=ABS(IF(B1=B2,J1-J2,0))"
Range("K1:O1").Copy
Range("K6:K" & Lstrow).PasteSpecial xlPasteFormulas
For Each i In Rng
If i < i.Offset(-1, 0) Then
Range("L" & i.Row).Value = "=O" & i.Row & "/n" & i.Row
Else
End If
Next i
End Sub

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
How can I calculate dates? Saz New Users to Excel 5 August 24th 07 03:24 PM
Calculate dates Carla Excel Worksheet Functions 1 May 4th 06 11:56 PM
calculate dates [email protected] Excel Discussion (Misc queries) 2 November 21st 05 07:04 PM
How do I calculate an age from 2 dates? UMMY Excel Worksheet Functions 3 August 2nd 05 10:36 PM
How do I calculate dates? MKChick Excel Worksheet Functions 2 April 15th 05 04:53 PM


All times are GMT +1. The time now is 10:33 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"