if user filter then

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
934
Dear all

May I know why my code doenst work. Any thing that I mislead?
My data is in filtermode but I havent filter anything yet. I want if i filter something then A1 = A
Code:
Private Sub Worksheet_Change(ByVal target As Range)

If ActiveSheet.AutoFilter Field:=1, Criteria1:="<>" Then

Range("A") = A

End If

End Sub

Thank you for your help
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi Vanda_3,
I think the problem with your code lies in Range("A") = A... First, you cant select range("A")... you could select range ("A:A") which would select the column A... Second you are setting it to A which is an unknown variable... maybe you want range("A1") = "A" or even range("A:A") = "A" or you want to set a variable for A and set the range to that variable....

Also of note: If you have your filter on, but nothing on the sheet is filtered, activesheet.filtermode will return false...

Hope this helps,

CN
 
Upvote 0
mistake on writing.

i meant Range("A1")

Although i change to below one still not work
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If ActiveSheet.FilterMode = True Then

Range("A1") = "A"

End If

End Sub
I have tried record macro to see what that the code is. I got this
Code:
ActiveSheet.AutoFilter Field:=1, Criteria1:="<>
but i cant get it work correctly

Code:
If ActiveSheet.AutoFilter Field:=1, Criteria1:="<> then
 
Last edited:
Upvote 0
I have my filter on but i dont filter anything yet. and when i filter something, i want the code is trigered
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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