VBA Worksheet_change or Worksheet_selectionchange not auto-triggered

dellzy

Board Regular
Joined
Apr 24, 2013
Messages
146
Hi Experts,

I have 2 worksheets which I coded (on each worksheet) to autofilter as per criteria whenever user select from the validation list. However, I don't know why it only works on the first worksheet. The 2nd worksheet only will autofilter when I click elsewhere and then click back the target cell. I tried to trick the macro to select other cell then select back the target cell upon selection made, but it still not working until I physically click the cells. Is there anyway to overcome this, please? Because I need to restrict the user to use only the validation list to filter the data and not meddle with the headers in the table. Been trying to solve this for 2 days already. ;(

Below is the code on the second worksheet:-

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Dim LastRow As Long


ActiveSheet.Unprotect Password:="abcd1234"


If Target.Address <> "$C$3" Then Exit Sub
If Target.Address = "$C$3" Then
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A4:AC" & LastRow).AutoFilter Field:=1, Criteria1:=Array(Range("$C$3"), "="), Operator:=xlFilterValues
ActiveSheet.Protect Password:="abcd1234"
End If
End Sub


Appreciate the experts' help.

Thank you in advance.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You need Worksheet_Change rather than Worksheet_SelectionChange if you want it to fire when you alter the dropdown. Using a dropdown doesn't change the selection.
 
Upvote 0
Hi Steve,

Thanks for the reply. Actually, I have tried using the Worksheet_Change before I use Worksheet_SelectionChange. But it didn't triggered anything even I click physically or not after selection. But it's funny that it works on the 1st worksheet. Only when I changed to Worksheet_SelectionChange then it triggers the job BUT after I click elsewhere then back to clicking the target cell. :(

I really don't understand what's holding it from doing upon selection. :(
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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