Calculate sum and rearrange rows to get value

Cimpcrro

New Member
Joined
Nov 16, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I have a table with positive and negative values in the same column and I need to order them so their sum at each row is closest to 0 and I need to do this based on article number.
For example, for article X I have the next order:
Book2
CD
1Item no.Value
2111100
3111200
4111-50
5111-70
6111-30
7111-40
8111-50
9111-80
10111-100
Sheet1

I need to rearrange it like this:

Book2
CD
12Item no.Value
13111100
14111-50
15111-70
16111200
17111-30
18111-40
19111-50
20111-80
21111-100
Sheet1


Thank you!
 
You are welcome.
I tried to document the code to explain what each step is doing, so hopefully it all makes sense.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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