View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
David Adamson[_4_] David Adamson[_4_] is offline
external usenet poster
 
Posts: 61
Default Combing an if then statement and an offset cell?

Robert

VBA is very subjective on how you do things. So yes you do get confused
looking at other peoples suggestions.
I would try something like this but there may be better suggestions out
there.

--------------------

Sub Name()
'Dim all your variables

'set what data you wish to look at
With Worksheets("Data Set")
'range (3a) = name 'after loop is will be 4a,etc
Set Name = .cells (2+i,1)
'discount for Name is in cell 3c, after it loops it will be 4c,etc
Set Dis = .cells(2+i,3)

'find the fee 'send the data you need to analyse to your function and return
the value
FeeResult = fee(Assets, Dis)

'now paste the feeReult where you want it
'assumed that it will be pasted in same worksheet in 3d, after it loops
result will be pasted into 4d,etc
..cells(2+i, 4) = FeeResult
End With

Next i

End sub


Function fee(Assets as double, Dis as double)
' calculates annual management fee
SetTier
Select Case Assets
Case 1 To 499999.99
fee = (Assets * Tier1) * (1*(1-dis))
Case 500000 To 999999.99
fee = (500000 * Tier1 + (Assets - 500000) * Tier2) * (1*(1-dis))



















"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!