VBAtrainingwheels
New Member
- Joined
- May 10, 2020
- Messages
- 3
- Office Version
- 2019
- Platform
- Windows
Hi
Have been learning VBA for ~24 hrs, so apologies what may be a straightforward question, but I am trying to write a code for the following:
Have been learning VBA for ~24 hrs, so apologies what may be a straightforward question, but I am trying to write a code for the following:
- I have the following rows of data in my sheet:
- Row 21 in my sheet is a row of binary flag that either equals 1 or 0
- Row 35 is a row of input values
- Row 39 is a row of formulas calculating a percentage between 0% and 100%
- I would like to code the following logic:
- If F21 <> 0, then GoalSeek M39 to equal 0.5 by changing cell F35
- If F21 = 0, then move one column to the right (for each cell mentioned above)
- Repeat until end the end of the range of binary flags in Row 21
VBA Code:
Sub DebtSize ()
‘Defined vairables
SevenYearPaydown = 0.5
FirstPaydownTest = Range(“M39”)
LastPaydownTest = Cells(39, Columns.Count).End(xlToLeft).Column
OpeningDebt = Range(“F35”)
FinalPeriodDebt = Cells(35, Columns.Count).End(xlToLeft).Column
FirstFlag = Range(“F21”)
LastFlag = Cells(21, Columns.Count).End(xlToLeft).Column
‘Debt sizing code
For x = FirstFlag To LastFlag
If FirstFlag <> 0 Then
FirstPaydownTest.GoalSeek Goal:=SevenYearPaydown, ChangingCell:=OpeningDebt
End If
Next x
End Sub