bobkap
Active Member
- Joined
- Nov 22, 2009
- Messages
- 323
- Office Version
- 365
- Platform
- Windows
- Mobile
- Web
I'm trying to perfect a simple macro that calculates profit margin based on 3 different conditions: 1) I have cost and desired margin but missing price; 2) I have price and desired margin but missing cost; 3) I have cost and price but missing margin calculation.
I've listed my code below but if my condition is met at either the first of second scenario I'm not sure how to end the routine there. Any help would be most appreciated.
I've listed my code below but if my condition is met at either the first of second scenario I'm not sure how to end the routine there. Any help would be most appreciated.
VBA Code:
Sub GMBK()
'
' GMBK Macro
'
cost = Range("b4").Value
Price = Range("c4").Value
margin = Range("d4").Value
If IsEmpty(Cells(4, 4)) Then
netp = Price - cost
margin = (netp / Price)
Cells(4, 4).NumberFormat = "0.0%"
Cells(4, 4) = margin
Else
If IsEmpty(Cells(4, 2)) Then
cost = Price / (1 - margin)
Else
If Price = cost / (1 - margin) Then
Cells(4, 3) = Price
End If
End If
End If
'
'
End Sub