Sorting macro skips the first row and begins sorting the second

Jonathan King

New Member
Joined
Dec 13, 2018
Messages
17
A simple sort routine is being used across a number of reports, but there's a few instances where the sort begins on the second row (row 13) and the not the first (row 12). It's strange, because the same code works fine in the majority of cases.

Any ideas?

Thanks in advance!

Sheets("Department").Select
Range("B12:D27").Select
ActiveWorkbook.Worksheets("Department").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Department").Sort.SortFields.Add2 Key:= _
Range("C12:C27"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Department").Sort
.SetRange Range("B12:D27")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
.Header:=xlYes

means you have a header row which is not included in the sort. Change it to

.Header:=xlNo

and try again.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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