Auto Unfilter when go to another sheet VBA

anna99

New Member
Joined
Jan 8, 2021
Messages
26
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
HI All,

I'm currently have current code as below, if activecell is empty or active cells count > 1, then exit sub; however, TargetCells.Count > 1 not working well, still shows an error. also, how do i insert code for "auto unfilter current worksheet when i go to another worksheet on the same workbook". thank you

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Value = "" Or Target.Cells.Count > 1 Then Exit Sub
Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:=ActiveCell.Value
End Sub

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Use
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Value = "" Or Target.CountLarge > 1 Then Exit Sub
Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:=ActiveCell.Value
End Sub
and to remove the filter put this in the same code window
VBA Code:
Private Sub Worksheet_Deactivate()
   Me.AutoFilterMode = False
End Sub
 
Upvote 0
Use
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Value = "" Or Target.CountLarge > 1 Then Exit Sub
Selection.AutoFilter Field:=ActiveCell.Column, Criteria1:=ActiveCell.Value
End Sub
and to remove the filter put this in the same code window
VBA Code:
Private Sub Worksheet_Deactivate()
   Me.AutoFilterMode = False
End Sub
Hi Fluff,

thank you i tried your code, but it returns an error Type 13, type mismatch. is there anyway just filter based on active cells of column A, also If Target.Value = "" Or Target.CountLarge > 1 Then Exit Sub (this is currently not working)
 
Upvote 0
What exactly are you trying to do?
 
Upvote 0
What exactly are you trying to do?
Hi Fluff,
Auto filter based on active cells of column A, so if you choose any value in column A, table will be filtered based on that value, if we choose any value NOT in column A then do nothing (Exit sub)
 
Upvote 0

Forum statistics

Threads
1,215,650
Messages
6,126,019
Members
449,280
Latest member
Miahr

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