how to add/sum two or more rows with similar cell value then put the result on the last row and delete the other similar rows (in VBA)?

gzesasaki

New Member
Joined
Jul 18, 2022
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Dear Sir/Madam,

can you please help me in resolving my issue on excel and what i am trying to do is to add/sum two or more rows with similar cell value then put the result on the last row (or overwrite the first row with the cell value being summed) and then delete the other rows with cell value being summed.

i am attaching an excel png as sample..
sample.png


" two rows with same value on coumn D ("WALK IN") then cell G should be added. And Im attaching also the required result..

result.png


thank you very much in advance..
gzesasaki
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the MrExcel board!

  1. Can we assume that any rows that contain the same value in column D will be next to each other like your sample?

  2. Can we assume that if rows to be combined have different values in some columns (eg column B for "WALK IN") then we keep the value in the higher row (apart from the summed column)?

It generally helps get faster answers in the forum if you provide your sample data in a form that can be copied to test with rather than a picture. MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
thank you for the reply sir peter,

Answer for 1, no Sir
and for number 2, Yes Sir as per the example attached..

:)
 
Upvote 0
Answer for 1, no Sir
In that case ..
  1. Could we have a small set of sample data and expected results (preferably with XL2BB) that includes at least one example where the same column D value occurs in 2 or 3 disjoint rows?

  2. Would it be acceptable to sort the data by column D so they are all together?
 
Upvote 0
RELIEF sales 092021DDDDDDD.xls
ABCDHIJKLMN
1Actions
2
3tax_monthseq_notinregistered_nameaddress1address2 gsales gtsales tax_rate touttax
4Tax MonthSeq. NoTIN NumberRegistered Name (For Non-Individuals)Substreet, Street, BrgyDistrict, City, Zip Code Gross Taxable Total Sales Taxable (Net of VAT) Tax Rate Total Output Tax
530/04/20221241556496000ANSON HOME INC25,000.0025,000.00-12.003,000.00
630/04/20222000106840000ANSON EMPORIUM CORPORATIONFull AddressMAKATI AVENUE AYALA CENTER MAKATI CITY47,928.5847,928.58-12.005,751.43
730/04/20223006899069000ANSON MARKETING AND COMMERCIAL INCFull AddressFILMORE STMAKATI CITY42,210.5842,210.58-12.005,065.27
830/04/20224000534418BOHOL I ELECTRIC COOP INCFull AddressDELIVERYBOHECO 1 WAREHOUSE1,241,785.751,241,785.75-12.00149,014.29
930/04/20225000542642000CABANATUAN ELECTRIC CORPFull AddressCABANATUAN CITY2,527,928.582,527,928.58-12.00303,351.43
1030/04/20226411502915000ELEMAX ENTERPRISESFull AddressNATL HIGHWAY SAN PEDRO MALLIG54,964.2554,964.25-12.006,595.71
1130/04/20227109537722ENGR ERNESTO GAYYADFull AddressKALINGA APAYAO(157,142.83)(157,142.83)-12.00(18,857.14)
1230/04/20228102109169FANM ENTERPRISESFull AddressBATASAN HILLS QUEZON CITY260,357.17260,357.17-12.0031,242.86
1330/04/20229000124374HONDA CARS PHILS INC LAGUNAFull AddressTECHNOPARK STA ROSA LAGUNA1,530,535.671,530,535.67-12.00183,664.28
1430/04/202210240570218000JFK POWER SALES CONSTRUCTIONFull AddressBgy Sucat Muntinlupa City1,164,937.501,164,937.50-12.00139,792.50
1530/04/202211005589352000KEVIN KARLO CORPFull AddressSt Sta Cruz Manila21,160.7521,160.75-12.002,539.29
1630/04/202212139130413000MPS CONSTRUCTION AND TRADINGFull AddressABAR 1ST SAN JOSE CITY203,062.50203,062.50-12.0024,367.50
1730/04/202213921830722000QSIX ELECTRICAL SALES ENGINEERINGFull AddressILAGAN ISABELA716,825.92716,825.92-12.0086,019.11
1830/04/202214215016032000RBF ENTERPRISESFull AddressDAMPOL 2ND PULILAN BULACAN586,285.75586,285.75-12.0070,354.29
1930/04/20221500041571300000TOYOTA MOTOR PHILIPPINES CORPORATIONFull AddressSta RosaTagaytay Highway Sta Rosa City Laguna3,667,099.083,667,099.08-12.00440,051.89
2030/04/202216223359036007WESTERN GRAND CENTRAL COINC FESTIVALFull AddressALABANGMUNTINLUPA CITY 177035,755.5835,755.58-12.004,290.67
2130/04/202217223359036006WESTERN GRAND CENTRAL COINC STA LUCIAFull AddressEAST GRAND MALL MARCOS HIGHWAY125,345.42125,345.42-12.0015,041.45
2230/04/202212000000000001WALK IN125,342.42125,342.42-12.0015,041.45
2330/04/202218223359036004WESTERN GRAND CENTRAL COINCTRINOMAFull AddressNorth Avenue COR EDSA40,938.5840,938.58-12.004,912.63
2430/04/202219000326100005WESTERN MARKETING CORPORATIONMORATOFull AddressFRANCISCO DEL MONTE16,573.6716,573.67-12.001,988.84
2530/04/202220000000000001WALK IN10,000.0010,000.00-12.001,200.00
Sales
Cell Formulas
RangeFormula
N25N25=(K25*0.12)
 
Upvote 0
Thanks for the sample data in a 'copyable' form. (y)

Would it be acceptable to sort the data by column D so they are all together?
.. or must the remaining rows be kept in the original relative order?


Also, there are a number of numerical columns on the right. Can you confirm which one (or ones) need to be summed as the rows are combined?
 
Upvote 0
Did a group by on the names and summed the sales and the tax with Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Columns" = Table.RemoveColumns(Source,{"Column1", "Column2", "Column3"}),
    #"Removed Top Rows" = Table.Skip(#"Removed Columns",1),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Top Rows",{{"tin", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"registered_name"}, {{"Sales", each List.Sum([#" gsales "]), type number}, {"Taxes", each List.Sum([#" touttax "]), type number}})
in
    #"Grouped Rows"
 
Upvote 0
Thanks for the sample data in a 'copyable' form. (y)


.. or must the remaining rows be kept in the original relative order?


Also, there are a number of numerical columns on the right. Can you confirm which one (or ones) need to be summed as the rows are combined?
yes sir, it is actually should be sorted according to column D.
thank you again..
:)
 
Upvote 0
Did a group by on the names and summed the sales and the tax with Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Columns" = Table.RemoveColumns(Source,{"Column1", "Column2", "Column3"}),
    #"Removed Top Rows" = Table.Skip(#"Removed Columns",1),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Top Rows",{{"tin", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"registered_name"}, {{"Sales", each List.Sum([#" gsales "]), type number}, {"Taxes", each List.Sum([#" touttax "]), type number}})
in
    #"Grouped Rows"
i am not yet familiar with power query sir..
:(
 
Upvote 0

Forum statistics

Threads
1,215,177
Messages
6,123,475
Members
449,100
Latest member
sktz

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