Error 91 concerning Objects or with Bloc but I dont have anything like this in my code

holy_eti

New Member
Joined
Jun 5, 2018
Messages
38
Hello, I have a small problem. My code is running half of the time. When I press on my command button, my code works fine. When I repress on it to try something else, my code isnt running and I have an error 91. I press on end and retry my command button and it works fine. I dont know what is my error so, can someone help me?
Here's my code. It stops running at the first ActiveWorkbook line's. Thank you
Code:
Dim check As Long
Dim archdata As Long
Dim t As Long
Dim t2 As Long
Dim rouge As Integer
Dim jaune As Integer


Dim moc_nombre_rap As Integer
Dim moc_nombre_archive As Integer
Dim k As Integer
Dim flag As Boolean

Worksheets("Données brutes").Activate
Worksheets("Données brutes").Range("E2").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.SortFields.Add Key _
    :=Range("E2:E213"), SortOn:=xlSortOnValues, Order:=xlAscending, _
    DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.Header = xlYes
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.MatchCase = False
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.Orientation = xlTopToBottom
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.SortMethod = xlPinYin
ActiveWorkbook.Worksheets("Données brutes").AutoFilter.Sort.Apply
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi there. I think the problem is that the second time through your code the line
Code:
Selection.AutoFilter
is turning it OFF, so the next line errors. To make sure the filter is always on, replace Selection.AutoFilter with:
Code:
  If Not ActiveSheet.AutoFilterMode Then
    Selection.AutoFilter
  End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top