VBA code to sum duplicate rows based on Uniuqe ID and t copy latest row based on date criteria

Status
Not open for further replies.

motherindia

Board Regular
Joined
Oct 15, 2015
Messages
218
Hello Sir,

I have 2 sheets. Sheet 1 contains 5 columns and Cust No is unique id. I need to combine the Column " Amt" based on Cust No and also to copy the latest value for Type /1002 against SAP Period in separate column. Output is shown below to be appeared on Sheet 2.

I need to automate to do this in VBA.
[TABLE="class: cms_table, width: 624"]
<tbody>[TR]
[TD="colspan: 2"]Input on Sheet 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Cust No[/TD]
[TD]Name[/TD]
[TD]SAP Period[/TD]
[TD]Type[/TD]
[TD]Amt[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]201005[/TD]
[TD]/1001[/TD]
[TD]-30,637.00[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]200804[/TD]
[TD]/1001[/TD]
[TD]-1,974.00[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]200805[/TD]
[TD]/1001[/TD]
[TD]1,000.00[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]C[/TD]
[TD]200810[/TD]
[TD]/1001[/TD]
[TD]-8,606.00[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]D[/TD]
[TD]200802[/TD]
[TD]/1001[/TD]
[TD]-2,074.00[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]D[/TD]
[TD]200803[/TD]
[TD]/1002[/TD]
[TD]-10,721.00[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]D[/TD]
[TD]200805[/TD]
[TD]/1002[/TD]
[TD]-2,531.00[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Output on Sheet 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Cust No[/TD]
[TD][/TD]
[TD]Total (/1001+/1002)[/TD]
[TD]//1002[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]-30,637.00[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]-974.00[/TD]
[TD]1,000.00[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]-8,606.00[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]-15,236.00[/TD]
[TD]-2,531.00[/TD]
[/TR]
</tbody>[/TABLE]


Regards,
motherindia
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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