Sort variable number of rows by column

BakerBaker

New Member
Joined
Feb 12, 2018
Messages
38
Office Version
  1. 2019
Platform
  1. Windows
Help greatly appreciated on this. Below is a simple representation of a larger data set. I wish to sort each block of rows by column with the numerical value in Col. B descending from Largest to Smallest.

Col. ACol.B
BirdsDogs
DogsBirds
HorsesHorses
Blank
CowsPigs
SheepSheep
PigsCows
GoatsGoats
Blank
PoultryHorses
CowsCows
HorsesDomestic
PigsOthers
OthersPigs
DomesticPoultry
Blank
etc.

Thanks

<tbody>
[TD="width: 113"]To give result:[/TD]
[TD="width: 85"]Col. A[/TD]
[TD="width: 64"]Col.B[/TD]

[TD="class: xl65"]9[/TD]

[TD="class: xl65"]14[/TD]

[TD="class: xl65"]14[/TD]

[TD="class: xl65"]9[/TD]

[TD="class: xl65"]3[/TD]

[TD="class: xl65"]3[/TD]

[TD="class: xl65"][/TD]

[TD="class: xl65"][/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"]16[/TD]

[TD="class: xl65"]11[/TD]

[TD="class: xl65"]11[/TD]

[TD="class: xl65"]16[/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"][/TD]

[TD="class: xl65"][/TD]

[TD="class: xl65"]3[/TD]

[TD="class: xl65"]34[/TD]

[TD="class: xl65"]22[/TD]

[TD="class: xl65"]22[/TD]

[TD="class: xl65"]34[/TD]

[TD="class: xl65"]14[/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"]11[/TD]

[TD="class: xl65"]11[/TD]

[TD="class: xl65"]4[/TD]

[TD="class: xl65"]14[/TD]

[TD="class: xl65"]3[/TD]

</tbody>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG12Feb20
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A:A").SpecialCells(xlCellTypeConstants)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Areas
    Dn.Resize(, 2).Sort Dn(1).Offset(, 1), xlDescending
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG12Feb20
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Set[/COLOR] Rng = Range("A:A").SpecialCells(xlCellTypeConstants)
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng.Areas
    Dn.Resize(, 2).Sort Dn(1).Offset(, 1), xlDescending
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick

Works a treat! Thanks for the fast reply.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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