Need help writing a MAX IF function

excel_noob14

New Member
Joined
Feb 24, 2018
Messages
3
I am a professed excel noob and so I need help writing this function. I need to write a function where a column of values will subtract from an original value until the value reaches zero.

If my original value is 125, I need the following table to look like this

B120
B220
B320
B420
B520
B620
B75

<tbody>
</tbody>

I need the function to be generic so that I can start with any original value and the function will subtract subtract 20 from that value until the value reaches less than 20 in the final cell.

hope this makes sense.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
excel_noob14, Good morning.

Scenario:
A1 --> TOTAL VALUE
B1 --> FIRST STEP

Try to use:
B2:B20 (adapt it to your reality)

formula -->
Code:
=IF(AND($A$1="",$B$1=""),"",MIN($B$1,$A$1-SUM($B$1:B1)))

Copy it down as necessary.

Is that what you want?

I hope it helps.
 
Upvote 0
Thanks for the reply. You could break down the formula a bit more for me. Like i said im a very much a beginner. What values do I replace the "" with?
AB
1125
220
420
520
620
720
820
95

<tbody>
</tbody>


If my table is like that with my original value of 125 and the values in the B column that I want, could you lay out the formula a bit more for me. Appreciate it
 
Upvote 0
Thanks for the reply. You could break down the formula a bit more for me. Like i said im a very much a beginner. What values do I replace the "" with?
AB
1125
220
420
520
620
720
820
95

<tbody>
</tbody>



If my table is like that with my original value of 125 and the values in the B column that I want, could you lay out the formula a bit more for me. Appreciate it
 
Upvote 0
excel_noob14, Good afternoon.

The first part of the formula means: If cell A1 AND cell B1 are empty then everything is empty.

In other words, do not do any calculations.
This is to avoid showing wrong calculations.

By the way, I will perfect the formula I sent you.
Instead of "AND" we will put "OR" in the formula.
So if either of the two cells is blank the calculation will not be done.

Let's also put a condition that if the result is zero or negative, that is, it has exceeded the established limit, the cell will be empty as well.
This helps in the aesthetic aspect of not filling the zeros cells.

In your first message you showed that the first value would be in cell B1.
The formula was created considering that the first value without formula would be in cell B1. (Reread my first message).

In your current drawing shows that you have nothing in cell B1 and the value is in cell B2.

Then in cell B2 you will enter the initial value(constant) and the formulas should be placed from B3 to wherever you want.

Now follows, the new formula considering all these observations of this message:

B3 -->
Code:
=IF(OR($A$1="",$B$2=""),"",IF(MIN($B$2,$A$1-SUM($B$2:B2))<=0,"",MIN($B$2,$A$1-SUM($B$2:B2))))
Copy it down as necessary.

I hope it helps.
 
Upvote 0
Good Day Try this

THX
Code:
Public Sub subtract()
Dim N As Long, R As Long, Q As Long
Dim L As Single
'N = 125' or
N = Range("A1")
S = 20 ' subtract Number
srw = 1 ' start row in column "B"
U = (N / S)
 Q = Application.Quotient(N, S)
  If N > (Q * S) Then Q = Q + 1
  Cells(srw, 2).Resize(Q + 2, 1).Clear 'clear Cell an One below more
    For R = 1 To Q
        L = N - ((R - 1) * S)
        If L >= S Then
            Cells(R + srw, 2) = S
                ElseIf L < S Then
             Cells(R + srw, 2) = L
        End If
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top