disabling autofilter mode after filter data based on cell value

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
108
Office Version
  1. 2016
Platform
  1. Windows
hello
I have this code but I would make autofilter mode = false after filter data I tried with this code but it doesn't so far
any idea to do that ,please ?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
 If Range("B2") = "All" Then

  Range("A3:E3").AutoFilter
 Else
  Range("A3:E3").AutoFilter Field:=2, Criteria1:=Range("B1")
  'ActiveSheet.AutoFilterMode = False
 End If
End If
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
Ok, try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
If Target.Address = "$B$1" Then
 If Range("B2") = "All" Then

  Range("A3:E3").AutoFilter
 Else
   With Range("A3:e3")
   For i = 1 To 5
      If i = 2 Then
         .AutoFilter i, Target.Value, , , 0
      Else
         .AutoFilter i, , , , 0
      End If
   Next i
   End With
 End If
End If
End Sub
 
Solution

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
108
Office Version
  1. 2016
Platform
  1. Windows
great ! but I have a question in your code used loop , is it necessary is not it possible without loop ?
 

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
108
Office Version
  1. 2016
Platform
  1. Windows
sorry I'm asking too much but what means comma before 0 sometimes you use 3 commas and 4 commas what means that
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Its just the position of the various arguments, where they are blank it means no argument is needed Range.AutoFilter method (Excel)
 

MKLAQ

Board Regular
Joined
Jan 30, 2021
Messages
108
Office Version
  1. 2016
Platform
  1. Windows
thank you so much for solution and assistance :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,137
Messages
5,640,329
Members
417,139
Latest member
madcabbie

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
Top