summing amount over previously selected cells based on one cell for more than name

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
Hello
I need sum amounts for columns D:F based on matching names in column C
so in cell H2 will select the name and should match with column C , then should sum amounts for all of names in I2:K2 after select the last name in H2
but every time I will select name in H1 then should sum over previous name is ever selected and when clear H2 then will I2:K2 is empty and start from the beginning
to understand more
CS.xlsm
ABCDEFGHIJK
1ITEMDETAILSNAMEDEBITCREDITBALANCENAMEDEBITCREDITBALANCE
21OPENING BALANCE 27/07/2023LLA6,000.007,000.00-1,000.00
32OPENING BALANCE 27/07/2023MLA6,000.0010,000.00-4,000.00
43OPENING BALANCE 27/07/2023ALAA4,000.001,000.003,000.00
54OPENING BALANCE 27/07/2023MAAL2,000.001,200.00800.00
6TOTAL18,000.0019,200.00-1,200.00
CS
Cells with Data Validation
CellAllowCriteria
H2:J2List=$C$2:$C$5


when i select name(LLA) from H1 will populate amounts I2:K2
CS.xlsm
ABCDEFGHIJK
1ITEMDETAILSNAMEDEBITCREDITBALANCENAMEDEBITCREDITBALANCE
21OPENING BALANCE 27/07/2023LLA6,000.007,000.00-1,000.00LLA6,000.007,000.00-1,000.00
32OPENING BALANCE 27/07/2023MLA6,000.0010,000.00-4,000.00
43OPENING BALANCE 27/07/2023ALAA4,000.001,000.003,000.00
54OPENING BALANCE 27/07/2023MAAL2,000.001,200.00800.00
6TOTAL18,000.0019,200.00-1,200.00
CS
Cells with Data Validation
CellAllowCriteria
H2List=$C$2:$C$5

when select another name(MLA) should sum over amounts for name is ever selected ( should merge amounts for names(LLA,MLA))
to become like this
CS.xlsm
ABCDEFGHIJK
1ITEMDETAILSNAMEDEBITCREDITBALANCENAMEDEBITCREDITBALANCE
21OPENING BALANCE 27/07/2023LLA6,000.007,000.00-1,000.00MLA12,000.0017,000.00-5,000.00
32OPENING BALANCE 27/07/2023MLA6,000.0010,000.00-4,000.00
43OPENING BALANCE 27/07/2023ALAA4,000.001,000.003,000.00
54OPENING BALANCE 27/07/2023MAAL2,000.001,200.00800.00
6TOTAL18,000.0019,200.00-1,200.00
CS
Cells with Data Validation
CellAllowCriteria
H2List=$C$2:$C$5

and if I select name(MAAL) then will merge amounts for names(LLA,MLA,MAAL) to become like this
CS.xlsm
ABCDEFGHIJK
1ITEMDETAILSNAMEDEBITCREDITBALANCENAMEDEBITCREDITBALANCE
21OPENING BALANCE 27/07/2023LLA6,000.007,000.00-1,000.00MAAL14,000.0018,200.00-4,200.00
32OPENING BALANCE 27/07/2023MLA6,000.0010,000.00-4,000.00
43OPENING BALANCE 27/07/2023ALAA4,000.001,000.003,000.00
54OPENING BALANCE 27/07/2023MAAL2,000.001,200.00800.00
6TOTAL18,000.0019,200.00-1,200.00
CS
Cells with Data Validation
CellAllowCriteria
H2List=$C$2:$C$5

and when clear H1 then should clear I2:K2 and start from the beginning
notice: if I repeat selection the name has already selected should not repeat merge (just merge one time not more for the same name)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this Worksheet_Change event code. If unsure how to implement it post back

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rfound As Range
  
  If Not Intersect(Target, Range("H2")) Is Nothing Then
    If Len(Range("H2").Value) = 0 Then
      Range("I2:K2").ClearContents
    Else
      Set rfound = Columns("C").Find(What:=Range("H2").Value, LookAt:=xlWhole)
      If Not rfound Is Nothing Then
        rfound.Offset(, 1).Resize(, 3).Copy
        Range("I2").PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd
        Application.CutCopyMode = False
      End If
    End If
  End If
End Sub
 
Upvote 1
Solution
seem to work perfectly without problem (y)
many appreciated for your help .:)
 
Upvote 0
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,079
Members
449,094
Latest member
mystic19

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