Performing a calculation in VBA based on conditional statements

Joined
Sep 6, 2006
Messages
3
Reaction score
0
Im having problems with the code enclosed by asterisks.
What im trying to do is to make the weight for each fund below row 79
go from 0% to 5% then back to 0% before moving on to the next fund (the
font for these funds below row 79 is red). When the fund is at a 5%
weight, I want to see what strategy it is (which will be in column B)
and find all the funds above row 80 that match that strategy and
perform a calculation on those funds.
the spreadsheet looks something like this

_______Column A____ Column B_______ Column D________ Column E
Row 1 ___Fund A _____________________3.20% __________Conv Arb
Row 2 ___Fund B______________________6.20%__________ Conv Arb
Row 79___Fund C _____________________4.10% __________Equity LS
Row 80_Short list A ____Conv Arb________ 5%
Row 81_Short list B____ Equity LS________ 0%



Dim i As Integer
Number = CountRed(Worksheets("AG").Range("A1:A110"))
For i = 1 To Number
Application.Goto Sheets("AG").Range("A79") 'this needs to reflect the cell above where the short list starts
ActiveCell.Offset(0 + i, 3).FormulaR1C1 = "5%"
*** For Each CellW In Worksheets("ag").Range("D4:D79") ' the ending cell needs to be the same as range above
If ActiveCell.Offset(0 + i, 3).Value = "5%" _
And CellW.Offset(0, 1).Text = ActiveCell.Offset(0 + i, 1).Text Then
CellW.Value = (Range("D:D").Value) / (Application.Sum(Range("D:D")) / (Application.Sum(Range("D:D")) - 0.05))***
Sheets("Summary").Range("D3").Offset(0 + i, 0).Value = Sheets("Summary").Range("C4").Value
Sheets("Summary").Range("H3").Offset(0 + i, 0).Value = Sheets("Summary").Range("G4").Value
Sheets("Summary").Range("P3").Offset(0 + i, 0).Value = Sheets("Summary").Range("O4").Value
Sheets("Summary").Range("T3").Offset(0 + i, 0).Value = Sheets("Summary").Range("S4").Value
Application.Goto Sheets("AG").Range("A79") 'this needs to reflect the cell above where the short list starts
ActiveCell.Offset(0 + i, 3).Select
ActiveCell.FormulaR1C1 = "0%"
End If
Next CellW
Next i

End Sub

Does anyone see anythign glaringly wrong wit this? Pls advise. Thx!
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top