Sort Data from Largest to smallest

bassemjohn1

Board Regular
Joined
Jun 26, 2020
Messages
51
Office Version
  1. 2016
Platform
  1. Windows
Hello All

so I need to sort my numbers in column K from Largest to smallest, the problem is I have another header in row 13 and it changes every month, what is the right VBA code to filter just the numbers and sort it from largest to smallest without messing with my headers in row 1 and 13.

1542001 - 2364001 Recon June- final 5.XLSX
KN
1Amount in local currencyEff.exchange rate
2-321.8740.37706
3-1,630.1110.37701
4-524.1250.37701
5-2,742.8190.37700
6-12,430.3790.37700
7-396.4470.37700
8672.4481.00000
9
10
11
12
13Amount in local currencyEff.exchange rate
141,630.1110.37701
15321.8741.00000
16524.1890.37706
172,742.8190.37700
1812,442.9800.37738
19396.5130.37706
BHR - BHC
 
If you are inserting formulas with vba then you have to double-up the quote marks within the formula.

VBA Code:
Range("L2").Formula = "=ROUND(ABS(K2),0)&"" - ""&COUNTIF(K$2:K2,K2)"
Range("M2").Formula = "=IF(COUNTIF($L$2:$L$292,L2)=2,""x"","""")"
Well noted, worked perfectly as i can see in column L, we rounded the numbers but if i don't want to round the numbers and just match based on the numbers before the decimals, can i do that ?
AS you can see in the below screenshot, the formula didn't match the -396.447 and 396.513 because it was rounded to 397
1661255694140.png
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
AS you can see in the below screenshot, the formula didn't match the -396.447 and 396.513 because it was rounded to 397
We could make those match by just ignoring the decimal part and looking at the whole number parts of the original numbers. In that case they would both be 396.
However, if we did that then -396.999 and 397.000 would not match because their whole number parts are different. yet these two numbers only differ by 0.001 yet the numbers highlighted yellow in your sample above differ by a larger amount of 0.066. Further, if we just ignore the decimals -396.000 and 396.999 would match even though they are almost 1 apart yet the very close numbers of -396.999 and 397.000 would not match.

That is why I asked earlier
How do you define what is a "minor difference" and what is a "major difference"?
 
Upvote 0
We could make those match by just ignoring the decimal part and looking at the whole number parts of the original numbers. In that case they would both be 396.
okay now I got your point, I will go with that option though, can we ignore the decimals altogether without rounding our numbers and matching based on the whole number parts, what can I add to the formula to achieve these results?

Also Thanks again for your continous support.
 
Upvote 0
can we ignore the decimals altogether without rounding our numbers and matching based on the whole number parts
Is this formula in column L better?

bassemjohn1.xlsm
KLM
1Amount in local currency
2-12430.37912430 - 1 
3-2742.8192742 - 1x
4-1630.1111630 - 1x
5-524.125524 - 1x
6-396.447396 - 1x
7-321.874321 - 1x
8672.448672 - 1 
9
10
11
12
13Amount in local currency
14321.874321 - 1x
15396.513396 - 1x
16524.189524 - 1x
171630.1111630 - 1x
182742.8192742 - 1x
1912442.9812442 - 1 
Sheet1 (4)
Cell Formulas
RangeFormula
L2:L8,L14:L19L2=INT(ABS(K2))&" - "&COUNTIF(K$2:K2,K2)
M2:M8,M14:M19M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
 
Upvote 0
Is this formula in column L better?

bassemjohn1.xlsm
KLM
1Amount in local currency
2-12430.37912430 - 1 
3-2742.8192742 - 1x
4-1630.1111630 - 1x
5-524.125524 - 1x
6-396.447396 - 1x
7-321.874321 - 1x
8672.448672 - 1 
9
10
11
12
13Amount in local currency
14321.874321 - 1x
15396.513396 - 1x
16524.189524 - 1x
171630.1111630 - 1x
182742.8192742 - 1x
1912442.9812442 - 1 
Sheet1 (4)
Cell Formulas
RangeFormula
L2:L8,L14:L19L2=INT(ABS(K2))&" - "&COUNTIF(K$2:K2,K2)
M2:M8,M14:M19M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
That's exactly what am looking for, you are awesome, and am really thankful for your time! and all the info i learned from you.
 
Upvote 0
@Peter_SSs sorry to bother you, but may I ask you why when running my macro today, it didn't capture some values and offset them together

GL Intercompany.XLSX
KLM
1Amount in local currencyRecon.Match
2-51.02051 - 1x
3-2,092.3722092 - 1x
4-149.340149 - 1 
5-8,373.0008373 - 1 
6-12.45512 - 1 
7-1,677.0601677 - 1x
8-121.843121 - 1x
9-345.160345 - 1 
10-2,978.7552978 - 1x
11-149.460149 - 1 
12-703.852703 - 1x
13-627.188627 - 1x
14-3,216.4483216 - 1x
15-3,517.5463517 - 1x
16-1,241.3131241 - 1x
17-117.320117 - 1x
18-77.24977 - 1 
19-965.334965 - 1x
20-834.041834 - 1x
21-77.24877 - 1 
22-37.69837 - 1x
230 - 0 
240 - 0 
250 - 0 
260 - 0 
27Amount in local currency#VALUE! 
2851.02051 - 1x
292,092.3722092 - 1x
30149.340149 - 1 
31121.840121 - 1x
322,978.7552978 - 1x
33149.460149 - 1 
34703.852703 - 1x
35627.188627 - 1x
368,385.4558385 - 1 
373,216.4483216 - 1x
383,517.5463517 - 1x
391,241.3131241 - 1x
401,677.0601677 - 1x
41117.320117 - 1x
4277.24977 - 1 
43965.334965 - 1x
44834.041834 - 1x
4577.24977 - 2 
4637.69837 - 1x
BHC - BHR
Cell Formulas
RangeFormula
L2:L46L2=INT(ABS(K2))&" - "&COUNTIF(K$2:K2,K2)
M2:M46M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")

As you can see, it didn't highlight rows L3 and L33, Although they have the same values, 149-1 and 149-1, same with amount 77 in rows 18,21, and rows 42,45.
 
Upvote 0
There is an issue with the Column L formula. However, to see what could be done about it, I would like to see the expected values in column L for that sample data.
Can you carefully fill in manually what values you would want in column L & column M and post that?
In particular, be careful with the '149' values and the '77' values since you have more than 2 of each of those in column K
 
Upvote 0
There is an issue with the Column L formula. However, to see what could be done about it, I would like to see the expected values in column L for that sample data.
Can you carefully fill in manually what values you would want in column L & column M and post that?
In particular, be careful with the '149' values and the '77' values since you have more than 2 of each of those in column K
yes sir

GL Intercompany.XLSX
KLM
1Amount in local currencyRecon.Match
2-51.02051 - 1x
3-2,092.3722092 - 1x
4-149.340149 - 1x
5-8,373.0008373 - 1 
6-12.45512 - 1 
7-1,677.0601677 - 1x
8-121.843121 - 1x
9-345.160345 - 1 
10-2,978.7552978 - 1x
11-149.460149 - 1x
12-703.852703 - 1x
13-627.188627 - 1x
14-3,216.4483216 - 1x
15-3,517.5463517 - 1x
16-1,241.3131241 - 1x
17-117.320117 - 1x
18-77.24977 - 1x
19-965.334965 - 1x
20-834.041834 - 1x
21-77.24877 - 1x
22-37.69837 - 1x
230 - 0 
240 - 0 
250 - 0 
260 - 0 
27Amount in local currency#VALUE! 
2851.02051 - 1x
292,092.3722092 - 1x
30149.340149 - 1x
31121.840121 - 1x
322,978.7552978 - 1x
33149.460149 - 1x
34703.852703 - 1x
35627.188627 - 1x
368,385.4558385 - 1 
373,216.4483216 - 1x
383,517.5463517 - 1x
391,241.3131241 - 1x
401,677.0601677 - 1x
41117.320117 - 1x
4277.24977 - 1x
43965.334965 - 1x
44834.041834 - 1x
4577.24977 - 2x
4637.69837 - 1x
BHC - BHR
Cell Formulas
RangeFormula
M46,M43:M44,M34:M41,M31:M32,M22:M29,M19:M20,M12:M17,M5:M10,M2:M3M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
L2:L46L2=INT(ABS(K2))&" - "&COUNTIF(K$2:K2,K2)


what to expect is highlighted in yellow, as -149.340 in row 3 should be offset against the positive value 149.340 in row 30, also -149.460 in row 11 should be offset against positive value 149.460 in row 33, and for 77.249 should be offset against the one in row 42. then in column M, every offset value from negative amounts against positive amounts should have x to be marked as done.

In particular, be careful with the '149' values and the '77' values since you have more than 2 of each of those in column K
that's the problem yes, that's why the formula didn't match these amounts against each other, what can we do so that even if I have 2 amounts in negative values that are the same to match with 2 amounts that are in positive value. like 77, 77 in L18 and L21 against -77 ,-77 in L42 and L45.
 
Upvote 0
In column L, I think you might need separate formulas for the top section and bottom section.

bassemjohn1.xlsm
KLM
1Amount in local currencyRecon.Match
2-51.0251 - 1x
3-2092.3722092 - 1x
4-149.34149 - 1x
5-83738373 - 1 
6-12.45512 - 1 
7-1677.061677 - 1x
8-121.843121 - 1x
9-345.16345 - 1 
10-2978.7552978 - 1x
11-149.46149 - 2x
12-703.852703 - 1x
13-627.188627 - 1x
14-3216.4483216 - 1x
15-3517.5463517 - 1x
16-1241.3131241 - 1x
17-117.32117 - 1x
18-77.24977 - 1x
19-965.334965 - 1x
20-834.041834 - 1x
21-77.24877 - 2x
22-37.69837 - 1x
23 
24 
25 
26 
27Amount in local currency 
2851.0251 - 1x
292092.3722092 - 1x
30149.34149 - 1x
31121.84121 - 1x
322978.7552978 - 1x
33149.46149 - 2x
34703.852703 - 1x
35627.188627 - 1x
368385.4558385 - 1 
373216.4483216 - 1x
383517.5463517 - 1x
391241.3131241 - 1x
401677.061677 - 1x
41117.32117 - 1x
4277.24977 - 1x
43965.334965 - 1x
44834.041834 - 1x
4577.24977 - 2x
4637.69837 - 1x
Sheet3
Cell Formulas
RangeFormula
L2:L22L2=INT(ABS(K2))&" - "&COUNTIF(L$1:L1,INT(ABS(K2))&" -*")+1
M2:M46M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
L28:L46L28=INT(K28)&" - "&COUNTIF(L$27:L27,INT(K28)&" -*")+1
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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