Hi,
I linked cell A1 to autofilter in A3, A1 get data from drop down list in C1.
the problem every time when I change value in C1, I need to click A1 than click F2 to work. see the attached file.
Your help is needed.
Thanks
Last edited by iskandak; 07-16-2011 at 06:34 AM.
Change the code to -
You dont need cell A1 then and the change event is recognised.Private Sub Worksheet_Change(ByVal Target As Range) Const WS_RANGE As String = "C1" '<== change to suit On Error GoTo ws_exit Application.EnableEvents = False If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then Me.Range("A3").AutoFilter field:=1, Criteria1:=Target.Value End If ws_exit: Application.EnableEvents = True End Sub
Dave H
You don't need the A1 reference, this will trigger properly off of C1. I added a "Show All" option that will unfilter the table, too. You can also delete the C1 value so it's blank to also unfilter the table.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Thank you for your replay,
What about if you want to get drop down from other page like A1 on Sheet 2. So that when you change the value on A1 on Sheet 2, the autofilter will change accordingly on Sheet .
The main thing in this issue is link the autofilter to other link or sheets.
See the attached file.
Thanks
It's still pretty much the same macro, you just move the event macro into the Sheet2 module, then edit the code to apply the filter commands on Sheet1. Like so...
Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo ws_exit Application.EnableEvents = False If Not Intersect(Target, [A1]) Is Nothing Then Select Case Target.Value Case "Show All", "" Sheets("Sheet1").AutoFilterMode = False Case Else Sheets("Sheet1").Range("A1").AutoFilter 1, Target.Value End Select End If ws_exit: Application.EnableEvents = True End Sub
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Thank a lot for your cooperation.
Solved.
Hi,
Autofilter not work with protect sheet.
See the attached file.
Thanks
The sheet you uploaded is working fine. Sheet2 is protected but the cell with the drop down is not protected thus you can still use the drop down, and that's all it takes to trigger the Autofilter on Sheet1 which is not protected.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Ah, I see what you mean. The simplest way to resolve running macro on protected sheets is to FIX the protection when then workbook opens so that you CAN run macro on the protected sheet. There is one parameter you can set when protecting a sheet called UserInterfaceOnly:=True that is added to a protection command so the protection no longer applies to VBA, only the the user. Macros are then free to do what they will on the protected sheet.
Simplest.... put this macro into a regular module1:
Sub ProtectData() Sheets("Sheet1").Protect _ DrawingObjects:=False, _ Contents:=True, _ Scenarios:=False, _ AllowFiltering:=True, _ UserInterfaceOnly:=True End Sub
Then put this macro into the ThisWorkbook module:
Private Sub Workbook_Open() ProtectData End Sub
The flag UserInterfaceOnly does not persist when the workbook is closed, it must be reactivated each time you open the workbook. So, this will do that. Also, if you unprotect sheet1 to work on it, reprotect it using the macro ProtectData so that flag gets set properly again.
Last edited by JBeaucaire; 07-14-2011 at 04:00 PM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Thank a lot
Solved.
If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks