vba code to split payment into date range

savo7us

New Member
Joined
Apr 11, 2019
Messages
1
hi
I have a problem am trying to build a forecast for my company and am using a formulas to fix this issue.
but it make the size of the sheet over 20 MB with the date that I used more the 5000 row so when i run the sheet it take time to open and calculate this formulas .
as far as I knew The VBA code could fix the size and the time to run this sheet
I found this code but I could not modify it to my requirement
Code:
Sub MG19Jul02()
Dim Rng As Range, Dn As Range, oMax As Date, oMin As Date, n As Long
Dim Lst As Long, Dic As Object
With Sheets("Sheet1")
    Set Rng = .Range(.Range("E2"), .Range("E" & Rows.Count).End(xlUp))
End With
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For n = 0 To -1 Step -1
    For Each Dn In Rng
        If n = 0 Then
            oMax = Application.Max(oMax, Dn.Offset(, n).Value)
            oMin = oMax
        Else
            oMin = Application.Min(oMin, Dn.Offset(, n))
        End If
    Next Dn
Next n
With Sheets("Sheet2")
     .Range("A1:c1").Value = Array("Contract", "Product", oMin)
    .Range("C1").AutoFill Destination:=.Range("c1").Resize(, DateDiff("m", oMin, oMax) + 1), Type:=xlFillMonths
    Lst = .Cells("1", Columns.Count).End(xlToLeft).Column
    .Range("C1").Resize(, Lst - 2).NumberFormat = "mmm-yy"
        For Each Dn In .Range("C1").Resize(, Lst - 2)
            Set Dic(Dn.Value) = Dn
        Next
        For Each Dn In Rng.Offset(, -1)
            If Dic.exists(Dn.Value) Then
                .Cells(Dn.Row, 1).Value = Dn.Offset(, -3).Value
                .Cells(Dn.Row, 2).Value = Dn.Offset(, -2).Value
                .Cells(Dn.Row, Dic(Dn.Value).Column).Resize(, Dn.Offset(, 2)).Value = Format(Dn.Offset(, -1).Value / Dn.Offset(, 2).Value, "0.000")
            End If
        Next Dn
End With
End Sub
my requirement is
I have 4 currency that am using in cell BO,BP,BQ and Br
the start dat of payment is in cell CD and end date is CE
the number of payment is in cell AH
what I need to do is
calculate the split the payment according to the number of months and if there is no payment in this month it recalculate and add this amount to the rest of the payment and if there is no payment for this row after the end date it be moved to next month as total
Note
started from cell CF3 I need it to automatically write the date as following ( mmm-yyyy currency ) and start from it finish to the next currency.
and it run automatically for the new entry without running the micro very time I add new entry



her is a link for this sheet
https://we.tl/t-lVBGdqx1KI

finally I appreciate your help and sorry for my way of typing cuz English is not my first language
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top