Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

If function

0

Please help me how i can write it using if function

overbook cost:  if showing up > capcity,  then difference between showing up  and capcity * overbook cost, otherwise =0 profit=revenue-variable cost-overbookcost)

Answer
Discuss

Answers

0

Hi Afnan and welcome to the Forum.

As Don says (in the second linked tutorial below), the IF function has 3 parts ":

=IF(logical_test, [value_if_true], [value_if_false])

The last two arguments have brackets around them because they are optional; if you leave them blank, they will just output the values True or False as a result of the function."

Your question is a little confusing but if I ignore from "profit=" onwards, then in the attached sample spreadsheet, you can change the values in following cells (shaded yellow):

  • B2= Capacity
  • B3= Overbook cost
  • B4= Showing up (whatever that means!)

and B6 has the IF formula:

=IF(B4>B2,(B4-B2)*B3,0)

where the central bit in bold is the (True) value if "Showing up" is greater than "Capacity" i.e. the difference between those numbers (B4-B2) multiplied by the "Overbook cost" B3. The brackets mean that difference number is calculated before the multiplication.

You just need to change the cell references to suit your case and put values into your new cells.

To learn more about IF, see Don's tutorial 15 IF Statement Examples in Excel. If you need to put an IF function within another ("nest" them) then see Nest IF Statements in Excel

Hope this helps.

Discuss

Discussion

No comment? 
John_Ru (rep: 6152) Feb 17, '22 at 6:15 pm
Afnan, just to remind you that you didn't respond to this Answer (and so didn't follow the Forum 's Rules - see hyperlink above right)
John_Ru (rep: 6152) Feb 28, '22 at 6:28 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login