I have an Excel Sheet with columns A through J. There are 1900 rows. The Numerical data to drive the sorting is in Column J2-J1900. There are formulas in Col K-O. The cells are protected, I do NOT want the rows in K-O to sort based on Column J . I DO want the rows A2 - I1900 to sort based on Col J sort
There is a header in row A
The sheet is password protected
I need a VBA code to sort rows based on Col J highest to lowest numerical value without impacting the sort of Col K-O
below is the code provided but I can't seem to get it to work
Sub SortData()
Dim ws As Worksheet
Dim lR As Long
Set ws = ThisWorkbook.Worksheets("Sheet1") ' your sheet
ws.Unprotect
lR = ws.Cells(ws.Rows.Count, "J").End(xlUp).Row
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("J2:J" & lastRow), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortNormal
.SetRange Range("A1:O" & lastRow) ' assuming A as start of columns
.Header = xlYes ' assuming you have headers
.Apply
End With
ws.Protect
End Sub
Any help, suggestions or solutions will be appreciated. /
Note this code was also posted on https://www.mrexcel.com/board/thread.../#post-6151933
Bookmarks