Hi
I'm trying to apply code to a workbook that has plenty other code going on already.
The workbook has a hidden sheet "Customers" and a frontend "Main" which cannot be sorted.
The sheets are named and I can apply macros to individual sheets, however I need to apply the macro to all except those specified.
Columns are named using enums.
I have code that deletes the contents of the sheets which I'm trying to modify to sort the sheets.
The first set of code below is in the "Main" sheet.
I hope to get this to work. Any help will be appreciated.
Private Sub Sort_Sheets(Optional ByVal FirstSheetOnly As Boolean)
' This will sort the specified sheets of the workbook
' "Not Identified" MUST be listed in first position
Const SheetsToSort As String = "Not Identified,Set1,Set2,Set3,Set4" & _
"Set5"
Dim Sn() As String
Dim ws As Worksheet
Dim Rng As Range
Dim Rl As Long
Dim i As Long
Application.ScreenUpdating = False
Sn = Split(SheetsToSort, ",")
For i = LBound(Sn) To UBound(Sn)
SortRange Sn(i)
If FirstSheetOnly Then Exit For
Next i
Application.ScreenUpdating = True
End Sub
Then in a module I have the following.
Sub SortRange(Sn As String)
Dim ws As Worksheet
Dim Rng As Range
Dim Rl As Long
On Error Resume Next
Set ws = ThisWorkbook.Worksheets(Sn)
If Err = 0 Then
Rl = LastRow(NrpKpiA, ws)
If Rl >= NrpFirstDataRow Then
Set Rng = Range(ws.Rows(NrpFirstDataRow), ws.Rows(Rl))
Range("A2:M500").Sort , _
Key1:=Range("K1"), _
Order1:=xlAscending
End If
End If
End Sub
I have looked everywhere and cannot find a solution.
Can somebody please help?