Hello, I have a workbook with multiple sheets and all but one of the sheets need to be sorted by date (found in column K). The sheet names vary by week so making this a static reference to a sheet name isn't possible. I'm having a bit of trouble establishing the range that will work with a loop.
With the code below I'm getting a Run Time Error 1004 saying the sort reference is not valid. I tried removing the ws from in front of the sort range and it works perfectly, but only for a single sheet.
I'm new to VBA so I apologize if this is easy. I've done many searches and can't find an answer.
Help please! Thanks!
Sub DateSort()
' Sort by date
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws
If WorksheetFunction.CountA(.Rows(2)) > 0 Then
ws.Range("K2").CurrentRegion.Sort key1:=Range("K2"), order1:=xlAscending, Header:=xlGuess
End If
End With
Next ws
Bookmarks