whitefeather
New Member
- Joined
- May 9, 2016
- Messages
- 29
Dears, I have a calculation table which outputs an 'instalment' (marked blue) amount by using goal-seek function by making a target cell to zero. Now the table is based on a specific row (marked green). I wish to run the same macro for 'n' count of rows (marked yellow in bellow example) and get the output in 'Instalment' cell of the respective row. The sheet as below:
Here is the code:
Thank you in advance.
EMI_SAMPLE_SHEET.xlsm | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | |||
1 | 1 | 25-Feb-23 | SL | Date | Instalment | Interest | Balance | Rate | Day Count | Accrual | FREQ | Contract Start | Payment Start | Loan Amount | Rate | Months | Accrual | Grace Month | Instalment | Goal_Seek Traget_Cell | ||
2 | 2 | 25-Mar-23 | 100.00 | 1 | 1-Feb-23 | 25-Feb-23 | 150,000.00 | 9.00 | 10 | 100.00 | 0 | 15,609.93 | 0.00 | |||||||||
3 | 3 | 25-Apr-23 | V_D | 1-Feb-23 | 150,000.00 | 9.00 | 24 | 900.00 | 1 | 7-Jan-23 | 27-Feb-23 | 201,620.00 | 9.00 | 6 | 4,362.00 | 0 | ||||||
4 | 4 | 25-May-23 | 1 | 25-Feb-23 | 15,609.93 | - | 134,390.07 | 9.00 | 28 | 940.73 | 1 | 13-Jan-23 | 20-Feb-23 | 271,649.00 | 10.00 | 5 | 1,526.00 | 1 | ||||
5 | 5 | 25-Jun-23 | 2 | 25-Mar-23 | 15,609.93 | - | 118,780.14 | 9.00 | 6 | 178.17 | 1 | 26-Jan-23 | 12-Feb-23 | 162,884.00 | 5.00 | 8 | 1,190.00 | 2 | ||||
6 | 6 | 25-Jul-23 | 31-Mar-23 | - | 2,118.90 | 120,899.04 | 9.00 | 25 | 755.62 | 1 | 24-Jan-23 | 6-Feb-23 | 728,973.00 | 9.00 | 8 | 1,405.00 | 2 | |||||
7 | 7 | 25-Aug-23 | 3 | 25-Apr-23 | 15,609.93 | - | 105,289.11 | 9.00 | 30 | 789.67 | 1 | 19-Jan-23 | 6-Feb-23 | 829,509.00 | 5.00 | 9 | 3,432.00 | 1 | ||||
8 | 8 | 25-Sep-23 | 4 | 25-May-23 | 15,609.93 | - | 89,679.18 | 9.00 | 31 | 695.01 | 1 | 22-Jan-23 | 8-Feb-23 | 607,074.00 | 10.00 | 7 | 3,412.00 | 0 | ||||
9 | 9 | 25-Oct-23 | 5 | 25-Jun-23 | 15,609.93 | - | 74,069.25 | 9.00 | 5 | 92.59 | 1 | 12-Jan-23 | 17-Feb-23 | 537,218.00 | 8.00 | 7 | 2,715.00 | 3 | ||||
10 | 10 | 25-Nov-23 | 30-Jun-23 | - | 2,332.89 | 76,402.14 | 9.00 | 25 | 477.51 | 1 | 2-Jan-23 | 27-Feb-23 | 383,124.00 | 12.00 | 8 | 2,224.00 | 2 | |||||
11 | 31-Mar-23 | 6 | 25-Jul-23 | 15,609.93 | - | 60,792.20 | 9.00 | 31 | 471.14 | 1 | 29-Jan-23 | 22-Feb-23 | 814,800.00 | 12.00 | 8 | 2,720.00 | 0 | |||||
12 | 30-Jun-23 | 7 | 25-Aug-23 | 15,609.93 | - | 45,182.27 | 9.00 | 31 | 350.16 | 1 | 28-Jan-23 | 16-Feb-23 | 163,790.00 | 6.00 | 5 | 2,413.00 | 2 | |||||
13 | 30-Sep-23 | 8 | 25-Sep-23 | 15,609.93 | - | 29,572.34 | 9.00 | 5 | 36.97 | |||||||||||||
14 | 31-Dec-23 | 30-Sep-23 | - | 1,335.78 | 30,908.12 | 9.00 | 25 | 193.18 | ||||||||||||||
15 | 9 | 25-Oct-23 | 15,609.93 | - | 15,298.19 | 9.00 | 31 | 118.56 | ||||||||||||||
16 | 10 | 25-Nov-23 | 15,609.93 | 311.74 | 0.00 | 9.00 | 36 | 0.00 | ||||||||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
J2 | J2 | =Q2 |
T2 | T2 | =INDEX(G:G,MATCH(P2,C:C,1)) |
D3 | D3 | =$L$2 |
G3 | G3 | =N2 |
H3:H16 | H3 | =$O$2 |
I3:I16 | I3 | =D4-D3 |
J3:J16 | J3 | =G3*H3%/360*I3 |
E4:E16 | E4 | =IF(AND(C4<>"",C4>$R$2,C4<=$P$2),$S$2,0) |
F4:F16 | F4 | =IF(OR(C4="",C4=$P$2),SUM(J$2:J3)-SUM(F$3:F3),0) |
G4:G16 | G4 | =G3-E4+F4 |
B1 | B1 | =$M$2 |
B2:B10 | B2 | =EDATE($B$1,ROWS($B$2:B2)*$K$2) |
B11 | B11 | =EOMONTH(L2,MOD(3-MONTH(L2),3)) |
B12:B14 | B12 | =EDATE(B11+1,3)-1 |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
C4:J403 | Expression | =ROUND($G3,0)=0 | text | NO |
Here is the code:
VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A1:B400").Select
Selection.Copy
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D4:D403") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("C4:D403")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("T2").GoalSeek Goal:=0, ChangingCell:=Range("S2")
End Sub
Thank you in advance.