I used the macro recorder and inserted the recorded code into the macro I'm using. I'm getting an error on the .sort section of the code stating "method or data member" not found. I'm not sure of the syntax to point to the current worksheet either. Thanks for your patience with me on this. Edit: I removed the (s) from the worksheet object and the code runs but it isn't sorting the data.
Sub x()
Dim n As Long, ws As Worksheet
Dim lrow As Long, sh As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
worksheetcount = ActiveWorkbook.Worksheets.Count
beginningrow = worksheetcount - 2
For i = beginningrow To Worksheets.Count
With Worksheets(i)
n = .Range("Q" & Rows.Count).End(xlUp).Row
.Range("S2:S" & n).Formula = "=(Q2-T2)/V2"
.Range("T2:T" & n).Formula = "=AVERAGE(Q$2:Q$" & n & ")"
.Range("U2:U" & n).Formula = "=MEDIAN(Q$2:Q$" & n & ")"
.Range("V2:V" & n).Formula = "=STDEV(Q$2:Q$" & n & ")"
.Range("W2:W" & n).Formula = "=SKEW(Q$2:Q$" & n & ")"
.Range("T2:W" & n).Value = .Range("T2:W" & n).Value
End With
Columns("S:S").Select
ActiveWorkbook.Worksheet.sort.SortFields.Clear
ActiveWorkbook.Worksheet.sort.SortFields.Add Key:= _
Range("S1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheet.sort
.SetRange Range("A2:W11")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Next i
End Sub
Bookmarks