
D3 will now subtract 5 from 25 in cell C3.
Then, select cell D3, enter the formula ‘ =C3-5‘ in the function bar and press the Return key. For example, enter the values ‘ 25,’ ‘ 35‘ and ‘ 55‘ in cells C3:C5. If you need to subtract a single value from each number within a cell range, you can copy the formula to other cells. Subtract One Number from Each Value within a Cell Range B5 will now return the value 200 as shown below. Input the formula ‘ =B3-B4‘ and press the Return key. Now, select cell B5 and click in the fx bar to enter a formula. For example, enter the values ‘ 345‘ and ‘ 145‘ in cells B3 and B4 in a blank Excel spreadsheet as in the snapshot below. To subtract cell values, you’ll need to include their row and column references in the formula instead. However, most Excel users will need to subtract numbers entered in spreadsheet columns and rows. The formula’s cell will return the value 20. For example, input ‘ =25-5‘ in the function bar and press Enter. Then click in the Excel function bar and input ‘ =‘ followed by the values you need to deduct. First, select a cell to add the formula to. QtyNumberB = QtyNumberB + Worksheets("Data").Cells(i, 2).Value QtyNumberA = QtyNumberA + Worksheets("Data").Cells(i, 2).ValueĮlseIf (Worksheets("Data").Cells(i, 1).Value = "B") Then If (Worksheets("Data").Cells(i, 1).Value = "A") Then QtyNumberRem = 0 'Variable for storing quantities remainingįor i = 2 To lLastRow 'scan all rows with data QtyNumberB = 0 'Variable for storing quantities of B QtyNumberA = 0 'Variable for storing quantities of A LLastRow = Worksheets("Data").Cells(2, 1).End(xlDown).Row 'Rows with data, starting 2nd row (titles in the first) Dim lLastRow As Longĭim QtyNumberA, QtyNumberB, QtyNumberRem As Integer It assumes the data is in a sheet named "Data", and that there is a button ( Button1) to run the code. Since we can't understand each other, take a look at the code below and try to rewrite it yourself to fit your needs.
What does "My formula below subtracts a cell until it reaches zero" mean? Also, as OldUgly pointed out, it seems that you are ignoring the second A.