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
 
it's From Column A:Z
Thank you!

Try this with a copy of your data.

VBA Code:
Sub SortGroupRows()
  Dim rA As Range
  
  For Each rA In Columns("K").SpecialCells(xlConstants, xlNumbers).Areas
    Intersect(rA.EntireRow, Columns("A:Z")).Sort Key1:=rA, Order1:=xlAscending, Header:=xlNo
  Next rA
End Sub
 
Upvote 0
Solution

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Thank you!

Try this with a copy of your data.

VBA Code:
Sub SortGroupRows()
  Dim rA As Range
 
  For Each rA In Columns("K").SpecialCells(xlConstants, xlNumbers).Areas
    Intersect(rA.EntireRow, Columns("A:Z")).Sort Key1:=rA, Order1:=xlAscending, Header:=xlNo
  Next rA
End Sub
Thank you sir !!! worked like a charm
 
Upvote 0
May I ask you another question please, I'm reconciling debit and credit amounts and it's matching perfectly using my VBA, except some amounts have minor changes in the decimals so the formula can't match them as they are not identical in amount

For EX:

1542001 - 2364001 Recon June- final 5.XLSX
KL
1Amount in local currencyRecon.
2-321.874321.874-1
3-1,630.1111630.111-1
4-524.125524.125-1
5-2,742.8192742.819-1
6-12,430.37912430.379-1
7-396.447396.447-1
8672.448672.448-1
9
10
11
12
13Amount in local currencyAmount in local currency-1
141,630.1111630.111-1
15321.874321.874-1
16524.189524.189-1
172,742.8192742.819-1
1812,442.98012442.98-1
19396.513396.513-1
BHR - BHC
Cell Formulas
RangeFormula
L13:L19,L2:L8L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))


As you can see the amounts in yellow are matching but there is a minor difference in the decimals that prevents them from matching, is there a tweak in my formula so I can make these amounts with minor decimal differences match also?
 
Last edited by a moderator:
Upvote 0
My Formulas are in column L and M
1542001 - 2364001 Recon June- final 5.XLSX
KLM
1Amount in local currencyRecon.Match
2-321.874321.874-1x
3-1,630.1111630.111-1x
4-524.125524.125-1 
5-2,742.8192742.819-1x
BHR - BHC
Cell Formulas
RangeFormula
L2:L5L2=IF(K2<0,-K2&"-"&COUNTIF(K$2:K2,K2),K2&"-"&COUNTIF(K$2:K2,K2))
M2:M5M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
 
Last edited by a moderator:
Upvote 0
Thank you sir !!! worked like a charm
You're welcome. :)
Just needed answers to those questions way back at post #3. ;)

As you can see the amounts in yellow are matching but there is a minor difference in the decimals that prevents them from matching, is there a tweak in my formula so I can make these amounts with minor decimal differences match also?
How do you define what is a "minor difference" and what is a "major difference"?

Also, are you looking for a change to the column L formula or the column M formula or both?

Also, your current column L formula could be simplified to
Excel Formula:
=ABS(K2)&"-"&COUNTIF(K$2:K2,K2)

BTW, no need to Quote something every time you post - only if it is relevant to the current post or indicating who you are replying to. I have removed some of your excess quotes as it makes your posts and the whole thread easier to read & follow.
 
Last edited:
Upvote 0
How do you define what is a "minor difference" and what is a "major difference"?

Also, are you looking for a change to the column L formula or the column M formula or both?

Also, your current column L formula could be simplified to
Excel Formula:
=ABS(K2)&"-"&COUNTIF(K$2:K2,K2)
By difference i mean: any difference in decimals as i don’t mind if there is a difference in decimals between my debits and credits

I am looking to change both column L and M formulas

Thank you for quick responses.
 
Upvote 0
By difference i mean: any difference in decimals as i don’t mind if there is a difference in decimals between my debits and credits
Is this what you mean then?
Change to column L formula only.

bassemjohn1.xlsm
KLM
1Amount in local currency
2-12430.37912430-1 
3-2742.8192743-1x
4-1630.1111630-1x
5-524.125524-1x
6-396.447396-1 
7-321.874322-1x
8672.448672-1 
9
10
11
12
13Amount in local currency
14321.874322-1x
15396.513397-1 
16524.189524-1x
171630.1111630-1x
182742.8192743-1x
1912442.9812443-1 
Sheet1 (4)
Cell Formulas
RangeFormula
L2:L8,L14:L19L2=ROUND(ABS(K2),0)&"-"&COUNTIF(K$2:K2,K2)
M2:M8,M14:M19M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
 
Upvote 0
Is this what you mean then?
Change to column L formula only.

bassemjohn1.xlsm
KLM
1Amount in local currency
2-12430.37912430-1 
3-2742.8192743-1x
4-1630.1111630-1x
5-524.125524-1x
6-396.447396-1 
7-321.874322-1x
8672.448672-1 
9
10
11
12
13Amount in local currency
14321.874322-1x
15396.513397-1 
16524.189524-1x
171630.1111630-1x
182742.8192743-1x
1912442.9812443-1 
Sheet1 (4)
Cell Formulas
RangeFormula
L2:L8,L14:L19L2=ROUND(ABS(K2),0)&"-"&COUNTIF(K$2:K2,K2)
M2:M8,M14:M19M2=IF(COUNTIF($L$2:$L$292,L2)=2,"x","")
i tried to add the new formulas to my VBA but an error of mismatch occurs
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","")"
 
Upvote 0
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"","""")"
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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