summing new value over the previous value based on more than item

Alaa mg

Active Member
Joined
May 29, 2021
Messages
375
Office Version
  1. 2019
hello
can I sum the new value in cell F6 over the prevouis value in cell F6 based on item in cell F2
F2 depends on column B , F6 depends on column C
when select A001 it will be
1.xlsx
ABCDEF
1ITEMCOSTITEM
2A0011000A001
3A0021500
4A0032900
5A004100TOTAL
61000
Sheet1

and when select different item should sum over previous value like this
1.xlsx
ABCDEF
1ITEMCOSTITEM
2A0011000A002
3A0021500
4A0032900
5A004100TOTAL
62500
Sheet1
 
Hi Alla,
If the item in cell F2 will match with any item in column B, the code I gave you will work with no errors.
The code below will inform you if you will have an invalid Item name in F2 or it will have no value (blank)
VBA Code:
Sub GetTotal()
    Dim WledVal As Long
    On Error GoTo 1001
    WledVal = Application.VLookup(Range("F2"), Range("B2:C5"), 2, 0)
    Range("F6").Value = Range("F6").Value + WledVal
    Exit Sub
1001 MsgBox "Invalid Item in cell F2"
End Sub
I hope this will help.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,786
Messages
6,174,551
Members
452,572
Latest member
KP53

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