if value in Column "N"<0 then
cost avoidance = 0

if value in Column "U" = "Services" then
A = market price USD - Line Amount USD
if A < 0 then
A = List Price - Line Amount USD
end if

if A still < 0 then
replace all -ve value = 0
end if

else if value in Column "U" <> "Services" then
A = (market price - unit price)*Qty
if A < 0 then
A = (list price - unit price)*Qty
end if

if A still < 0 then
replace all -ve value = 0
end if

I would like to transform this code to an IF formula instead of looping. This code is going to place only in one cell. Anyone can help me for this thing?