About a year ago I had someone help me with a re-aging function. It essentially took a bad aging report and fixed it, via a function.
For example, if I had these values:
Current 31- 60 61- 90 91- 120 121 & Over Future
(373.00) 0.00 0.00 472.00 0.00 0.00
It would take the current and net it against the 91-120 to have only 99.00 in the 91-120. The code includes stuff for some odd situations, and apparantly there is a new one this year that throws off the calculation.
If I have these values:
Current 31- 60 61- 90 91- 120 121 & Over Future
(128.80) 116.04 0.00 0.00 0.00 0.00
The function is returning -128.80 in Current instead of -12.76 in current.
I believe it has something to do with the total amount due being less than zero and it throws off the calculation.
The way I use the above function is actually like an array...I would enter this formula into 6 cells and confirm with CTRL-SHIFT-ENTER:
=IF($S2=1,aging($I2:$N2),"")
Can someone review the code and possibly identify where it needs to be tweaked? I greatly appreciate it (the code grew beyond my comprehension last year, so I have difficulty figuring out exactly what it is doing).
Thanks!
Function Aging(rg As Range)
Dim temp() As Variant
ReDim temp(1 To rg.Columns.Count)
For i = 1 To rg.Columns.Count
temp(i) = rg(i)
Next
themin = Application.Min(rg)
If themin >= 0 Then
Aging = rg
Exit Function
End If
'assumes 1 negative
'if there are >1 positive with future=0 then apply current right-to-left
If temp(1) = 0 And temp(2) < 0 And Application.CountIf(rg, ">0") > 1 Then
Again:
For i = 6 To 3 Step -1
If temp(i) > 0 Then
If Abs(temp(2)) < temp(i) Then
temp(i) = temp(i) + temp(2)
temp(2) = 0
GoTo 1
Else
temp(2) = temp(2) + temp(i)
temp(i) = 0
GoTo Again
End If
End If
Next
End If
leftover = Application.Sum(temp)
If leftover > 0 Then
If temp(1) > 0 Then
For i = 2 To rg.Columns.Count
temp(i) = 0
Next
temp(1) = leftover
Else
For i = 2 To rg.Columns.Count
If temp(i) > 0 Then temp(i) = leftover Else temp(i) = 0
Next
End If
Else
For i = 2 To rg.Columns.Count
If temp(i) < 0 Then temp(i) = leftover Else temp(i) = 0
Next
End If
For i = 2 To 5
If temp(i) <> 0 Then
For j = i + 1 To 6
temp(j) = 0
Next
End If
Next
n = 0
For i = 1 To 6
If temp(i) <> 0 Then n = n + 1
Next
If n > 1 Then temp(1) = 0
1:
Aging = temp
End Function
One interesting note:
Although this doesn't work right:
Current 31- 60 61- 90 91- 120 121 & Over Future
(128.80) 116.04 0.00 0.00 0.00 0.00
If you change it around a bit it will work right:
Current 31- 60 61- 90 91- 120 121 & Over Future
116.04 (128.80) 0.00 0.00 0.00 0.00
Bookmarks