Romano_odK
Active Member
- Joined
- Jun 4, 2020
- Messages
- 380
- Office Version
- 365
- Platform
- Windows
Good afternoon,
The below code was working fine last year and in the meanwhile nothing has changed expect the domain where I am working in. Can someone tell me why I get this error? "Sort method of range class failed"
Thank you for your time and all the best wishes for 2024.
The below code was working fine last year and in the meanwhile nothing has changed expect the domain where I am working in. Can someone tell me why I get this error? "Sort method of range class failed"
Thank you for your time and all the best wishes for 2024.
VBA Code:
Private Sub FilterOK_Click()
Dim a As Variant, b As Variant
Dim nc As Long, i As Long, k As Long
nc = Range("ItemsImport").Columns.Count + 1
a = Range("ItemsImport[[#All],[Afwijking %" & Chr(10) & "Opslag]]").Value
ReDim b(1 To UBound(a), 1 To 1)
For i = 1 To UBound(a)
If LCase(a(i, 1)) = "ok" Or Len(a(i, 1)) = 0 Then
b(i, 1) = 1
k = k + 1
End If
Next i
If k > 0 Then
Application.ScreenUpdating = False
With Range("ItemsImport[#All]").Resize(, nc)
.Columns(nc).Value = b
.Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlYes
.Offset(1).Resize(k).EntireRow.Delete
.Columns(nc).EntireColumn.Delete
End With
Application.ScreenUpdating = True
End If
End Sub