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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.