![]() |
VBA problems
I've been trying to create a macro that will do the following: I want
the macro to loop through a bunch of funds and calculate what would happen if we allocated 5% to the fund. I have about 20 funds I want to loop through, all start out with a weight of zero. I then chnage the 0% to 5% for one fund at a time and copy the resulting volatility (calcualted iwth the new weight) onto a separate spreadsheet called Summary. C4 links to the new volatility on the AG spreadsheet, but needs to be copied,pasted each time since the link stays the same but the value obviuolsy changes as the weight is updated (im also doing this with returns and betas/correlations, hence the "G4", "O4" and "S4"). im encountering a few problems--the macro is giving me problems with the 2 separately named spreadsheets (I get the error Select method of range class failed). Then I was also havign a problem with the paste special function. any suggestions? Is this set up completely wrong??? Worksheets("AG").Range("A76").Select For i = 0 To 20 Do Until i = 20 ActiveCell.Offset(0 + i, 3).Select ActiveCell.FormulaR1C1 = "5%" Worksheets("Summary").Range("C4").Select Selection.Copy ActiveCell(0 + i, 1).Range("C4").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone Worksheets("Summary").Range("G4").Select Selection.Copy ActiveCell(0 + i, 1).Range("G4").Select Selection.PasteSpecial Paste:=xlPasteValues Worksheets("Summary").Range("O4").Select Selection.Copy ActiveCell(0 + i, 1).Range("o4").Select Selection.PasteSpecial Paste:=xlPasteValue Worksheets("Summary").Range("S4").Select Selection.Copy ActiveCell(0 + i, 1).Range("S4").Select Selection.PasteSpecial Paste:=xlPasteValue Worksheets("AG").Range("A76").Select ActiveCell.Offset(0 + i, 3).Select ActiveCell.FormulaR1C1 = "0%" Loop Next i End Sub |
All times are GMT +1. The time now is 06:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com