Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function ProjectSales(forMonth As Date, salesLastMonth As Integer, salesLastMonthYear As Integer, salesCurrentMonthYear As Integer) As Double
  2.     Dim DC As Integer ' days in the current month
  3.    Dim DL As Integer ' days in last month
  4.    Dim DLY As Integer ' days in last month one year ago
  5.    Dim DCY As Integer ' days in the current month one year ago
  6.  
  7.     DC = DaysInMonth(forMonth)
  8.     DL = DaysInMonth(DateAdd("m", -1, forMonth))
  9.     DLY = DaysInMonth(DateAdd("m", -13, forMonth))
  10.     DCY = DaysInMonth(DateAdd("m", -12, forMonth))
  11.    
  12.     Dim SL As Integer ' sales in the last month
  13.    Dim SLY As Integer ' sales in the last month one year ago
  14.    Dim SCY As Integer ' sales in the current month one year ago
  15.    SL = salesLastMonth
  16.     SLY = salesLastMonthYear
  17.     SCY = salesCurrentMonthYear
  18.    
  19.     Dim m As Double ' slope of the sales rate from the months last year
  20.    m = ((SCY / DCY) - (SLY / DLY)) / ((DCY + DLY) / 2)
  21.    
  22.     ' our x = 0 is halfway through the last month.  Find the dates of the start and end of the current month based on our x
  23.    Dim monthStart As Double
  24.     Dim monthEnd As Double
  25.     monthStart = DL / 2
  26.     monthEnd = monthStart + DC
  27.    
  28.     ProjectSales = m * (monthEnd ^ 2 / 2) + (SL / DL) * monthEnd - (m * (monthStart ^ 2 / 2) + (SL / DL) * monthStart)
  29. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement