Reputation: 21
Can you help me with the proper code to used in VBA excel? For example if in column A , A1 text is BUY, I would like to perform a certain formula in the next column which is B1, wherein the formula would be like =c4+c5+(d1*c6)+(d1*c7)
and when if the text in column A is SELL, the formula will be =c4+c5+(d1*c6)+(d1*c7)+(d1*c6)
and for the rest, the calculations will be automatic when the condition on buy or sell is met. Thank you
Upvotes: 1
Views: 96
Reputation: 128
Public Sub NameOfYourSub()
Dim rg as Range
Set rg= Range("NameOfTheCellToCheck")
If rg.value = "BUY" Then
Set rg.offset(0,1).Value= YOUR BIG FORMULA (don't forget to use Range("NameOfTheCell").value +/*.....)
//Otherwise
//Range("NameOfTheCellWhereToPutTheResult")=YOUR BIG FORMULA
Else
//The same syntax as above.
End If
Set rg= Nothing
End Sub
Upvotes: 1
Reputation: 2898
So you just want to add the following formula to B1? No VBA needed.
= C4 + C5 + D1*C6*IF(A1="BUY", 1, 2) + D1*C7
Upvotes: 2