Multiple block sorting

rjplante

Well-known Member
Joined
Oct 31, 2008
Messages
567
Office Version
  1. 365
Platform
  1. Windows
I have a block of cells from column A - H that can have a variable number of rows. The data set can also have multiple blocks of data separated by a single blank row. I need to have a macro that will start with row 3 and grab the first block from row 3 to the bottom of the block based on the data in column A, and then sort the data based on the values in Column E. Once that block is sorted, I need it to loop X number of times. I have cell BG1, that displays the number of blocks in the full table. I need the macro to loop through the sort protocol the total number displayed in cell BG1.

All of the cell block have the same number of rows, so if you were to go to cell A3 and use xlEndDown, you would have the total number of rows in each block. You could define that number of rows as a variable and use that in the loop.

I don't know how to write this macro to get through the sorting easily enough.

Please and thank you for any assistance with this.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Is column A hard values, or formulae?
Also does each block have a header row?
 
Upvote 0
Yes Column A is hard data. There are headers, but they span two rows. I have the top of the table pictured below. I need the second start date as the one to be sorted on. Column E.

PlanPlanPlanActualActualActual
JOB #Start Date# working daysEnd DateStart Date# working daysEnd DateColumn Header
44422-Apr-20196925-Jul-201922-Apr-20196925-Jul-2019Design
8888-Jul-201916826-Feb-20208-Jul-201916826-Feb-2020Electrical
 
Upvote 0
Do you have those header rows between each block of data, or just in rows 1 & 2?
 
Upvote 0
No there is no header row between blocks of data, just a single blank row.
 
Upvote 0
In that case, try
VBA Code:
Sub rjplante()
   Dim Rng As Range
   
   For Each Rng In Range("A3", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.Resize(, 8).Sort Rng.Offset(, 4), xlAscending, , , , , , xlNo
   Next Rng
End Sub
 
Upvote 0
That is so nice and short and it works perfect. Thanks for the nice little tidy bit of code.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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