VBA for sorting while ignoring negatives.

Dingle

New Member
Joined
Oct 17, 2018
Messages
2
F

G
H
I
J
8
-8
123
-8
7
3
-8
6
-8
-5
-4
5
132
-2
-3
131
5

-8
4
999

<tbody>
</tbody>
Dear all,


I’ve been struggling with the ending of my ratherlarge macro converting information out of our Financial bookkeeping system.

Little bit of context:
This is concerns outstanding invoices of clients,divided by client in rows and the amounts outstanding split in columns in a fewcategories. Categories being divided in:

  • Not due
  • 0-10 days due
  • 11-20 days due
  • 21-60 days due
  • 60> days due

There are numbers everywhere, mostly being positivenumbers.
The problem I face is that I try to have a Sortingcode in the macro, sorting the 5 columns, high to low(descending) but ignoring negativenumbers. It should look like this:


(Sorry, example of the table on top of the post, cant seem to get it here)



The sorting of the 0 or negatives is not important.

What have I tried?

1) Use ‘record macro’ and adjusting it with variables:

Rich (BB code):
 ActiveWorkbook.Worksheets("Blad1").Sort.SortFields.AddKey:=Range("F8", Range("F8").End(xlDown)), _
Rich (BB code):
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal

Hoped to be able to adjust the xlSortOnValues line orat alter the code.

2) I found this post on this forum; https://www.mrexcel.com/forum/excel-questions/1057699-vba-sort-ascending-descending-order-based-if-value-positive-negative.html
I have been trying to alter the code posted at may 31st,2018, 03:47PM, but unsuccessfully.

Now I have to admit, I’ve been using macro’s a lot byjust recording and altering the code to work on different variables. Myknowledge on VBA seems to be inferior.
Can any one perhaps push me in the right direction? Ifear to be needing to use Dimensions, which aren’t 100% clear for me yet.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Re: VBA Marco for sorting while ignoring negatives.

Welcome to the forum :)

1 are your headers in row 1 starting in A1?
2 does your data start in row 2?
3 which columns require sorting? (F G H I J ?)
4 is each column sorted separately and results evaluated or should columns be sorted together in a specific sequence of priority?
5 what is the sort order for each column (are all smallest to largest? )
 
Upvote 0
Re: VBA Marco for sorting while ignoring negatives.

Welcome to the forum :)

1 are your headers in row 1 starting in A1?
2 does your data start in row 2?
3 which columns require sorting? (F G H I J ?)
4 is each column sorted separately and results evaluated or should columns be sorted together in a specific sequence of priority?
5 what is the sort order for each column (are all smallest to largest? )

Thank you for your reply.
I’d hoped to have everything typed out as, so apologies for the missing info.


1) The information is set from A7 to O7 with the 7throw being headers. Data starting from Row 8. There is client info column A-Eand K-O but always only having this info starting in row 8. Columns F,G,H,I,Jcontains the criteria for the sorting, the entire row should shift. But basedon F to J

2) data starts row 8
3) The entire row (A-O) but based on F,G,H,I,J
4) These columns aren’t merged, not really sure whatyou mean with this question, but I hope to have answered this at nr 1.
5) Descending, Highest to lowest (excl. 0 /negatives).
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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