Below code give error msg 424 object required when it come to Usedrange.AutoFilter code line.
Code:
Sub WorkOrderListFile()
Dim sheet As Worksheet
Dim row_min As Integer
Dim row_max As Integer
Dim col_min As Integer
Dim col_max As Integer
' Select the used range.
Set sheet = ActiveSheet
sheet.UsedRange.Select
' Display the range's rows and columns.
row_min = sheet.UsedRange.Row
row_max = row_min + sheet.UsedRange.Rows.Count - 1
col_min = sheet.UsedRange.Column
col_max = col_min + sheet.UsedRange.Columns.Count - 1
'This code will unmerge all the merged cells
Worksheets("Report").Activate
ActiveSheet.UsedRange.Select
ActiveSheet.Cells.UnMerge
'This code will give SPOC names against work order
If Range("L1") = Empty And col_max > 9 Then
Range("L1").Select
Selection.Delete Shift:=xlUp
'This code will delete all empty cells and move to left
Cells.Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift:=xlToLeft
'This will make all columns autofit
'Cells.Columns.AutoFit
sheet.UsedRange.Select
Set ws = ThisWorkbook.Worksheets("Report")
ws.Activate 'not required but allows user to view sheet if warning message appears
'Clear any existing filters
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
'1. Apply Filter
With UsedRange
UsedRange.AutoFilter field:=1, Criteria1:="<>Work Order:"
End With
'2. Delete Rows
Application.DisplayAlerts = False
UsedRange.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
'3. Clear Filter
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
Cells.Columns.AutoFit
ActiveSheet.UsedRange.Select
Dim rng As Range, cell As Range
Set rng = Selection
For Each cell In rng
cell.Value = Replace(cell.Value, " ", " ")
' cell.Font.Color = vbRed
cell = Trim(cell)
Next cell
End If
End Sub