Macro Looping for 'n' counts of rows

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:

EMI_SAMPLE_SHEET.xlsm
ABCDEFGHIJKLMNOPQRST
1125-Feb-23SLDate Instalment Interest Balance Rate Day Count Accrual FREQContract StartPayment StartLoan AmountRateMonthsAccrualGrace Month Instalment Goal_Seek Traget_Cell
2225-Mar-23100.0011-Feb-2325-Feb-23150,000.009.0010100.00015,609.930.00
3325-Apr-23V_D1-Feb-23150,000.009.0024900.0017-Jan-2327-Feb-23201,620.009.0064,362.000
4425-May-23125-Feb-2315,609.93-134,390.079.0028940.73113-Jan-2320-Feb-23271,649.0010.0051,526.001
5525-Jun-23225-Mar-2315,609.93-118,780.149.006178.17126-Jan-2312-Feb-23162,884.005.0081,190.002
6625-Jul-2331-Mar-23-2,118.90120,899.049.0025755.62124-Jan-236-Feb-23728,973.009.0081,405.002
7725-Aug-23325-Apr-2315,609.93-105,289.119.0030789.67119-Jan-236-Feb-23829,509.005.0093,432.001
8825-Sep-23425-May-2315,609.93-89,679.189.0031695.01122-Jan-238-Feb-23607,074.0010.0073,412.000
9925-Oct-23525-Jun-2315,609.93-74,069.259.00592.59112-Jan-2317-Feb-23537,218.008.0072,715.003
101025-Nov-2330-Jun-23-2,332.8976,402.149.0025477.5112-Jan-2327-Feb-23383,124.0012.0082,224.002
1131-Mar-23625-Jul-2315,609.93-60,792.209.0031471.14129-Jan-2322-Feb-23814,800.0012.0082,720.000
1230-Jun-23725-Aug-2315,609.93-45,182.279.0031350.16128-Jan-2316-Feb-23163,790.006.0052,413.002
1330-Sep-23825-Sep-2315,609.93-29,572.349.00536.97
1431-Dec-2330-Sep-23-1,335.7830,908.129.0025193.18
15925-Oct-2315,609.93-15,298.199.0031118.56
161025-Nov-2315,609.93311.740.009.00360.00
Sheet1
Cell Formulas
RangeFormula
J2J2=Q2
T2T2=INDEX(G:G,MATCH(P2,C:C,1))
D3D3=$L$2
G3G3=N2
H3:H16H3=$O$2
I3:I16I3=D4-D3
J3:J16J3=G3*H3%/360*I3
E4:E16E4=IF(AND(C4<>"",C4>$R$2,C4<=$P$2),$S$2,0)
F4:F16F4=IF(OR(C4="",C4=$P$2),SUM(J$2:J3)-SUM(F$3:F3),0)
G4:G16G4=G3-E4+F4
B1B1=$M$2
B2:B10B2=EDATE($B$1,ROWS($B$2:B2)*$K$2)
B11B11=EOMONTH(L2,MOD(3-MONTH(L2),3))
B12:B14B12=EDATE(B11+1,3)-1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C4:J403Expression=ROUND($G3,0)=0textNO


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.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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