blucloudysky13
New Member
- Joined
- May 7, 2011
- Messages
- 2
Hi guys,
I am having a lot of difficulty trying to figure out how the macros work. I've looked at several forums and guides for several hours now trying to understand it, but I can't.
I am doing a financial model. I have a list of bonds with maturity dates and an input for the date of today. If the date of today is over the expiration date, the value = NA. So, I am trying to filter out values in a list that are =NA and then using Solver to find the weights I need on the list of bonds that have values. But, then when I change the date to something higher, the Solver messes up and it starts to put in values in another column or above/below where it should be. Please help me! I am a newbie when it comes to macros, but I really would like to understand how it's supposed to work. Here is what's on the VBA:
Sheets("Bonds").Select
ActiveSheet.AutoFilter.ApplyFilter
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveCell.Offset(-25, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
SolverReset
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$V$16:$V$41", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$V$43", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="$W$43", Relation:=2, FormulaText:="$R$43"
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Sheets("Planned Budget Balance Sheet").Select
ActiveCell.Offset(-1, 0).Range("A1").Select
Let me know if my explanation of what I'm trying to do is unclear. Thank you!
I am having a lot of difficulty trying to figure out how the macros work. I've looked at several forums and guides for several hours now trying to understand it, but I can't.
I am doing a financial model. I have a list of bonds with maturity dates and an input for the date of today. If the date of today is over the expiration date, the value = NA. So, I am trying to filter out values in a list that are =NA and then using Solver to find the weights I need on the list of bonds that have values. But, then when I change the date to something higher, the Solver messes up and it starts to put in values in another column or above/below where it should be. Please help me! I am a newbie when it comes to macros, but I really would like to understand how it's supposed to work. Here is what's on the VBA:
Sheets("Bonds").Select
ActiveSheet.AutoFilter.ApplyFilter
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 15
ActiveCell.Offset(-25, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "0%"
ActiveCell.Offset(1, 0).Range("A1").Select
SolverReset
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$V$16:$V$41", Relation:=3, FormulaText:="0"
SolverAdd CellRef:="$V$43", Relation:=2, FormulaText:="1"
SolverAdd CellRef:="$W$43", Relation:=2, FormulaText:="$R$43"
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$X$43", MaxMinVal:=1, ValueOf:=0, ByChange:="$V$16:$V$41", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Sheets("Planned Budget Balance Sheet").Select
ActiveCell.Offset(-1, 0).Range("A1").Select
Let me know if my explanation of what I'm trying to do is unclear. Thank you!