• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Running macros by assigning them to values in drop down list

ysherriff

Member
Hi all,

I need help in calling a macro from the selected dropdown. The name of the macro to call is State_Selection.

here is the code based on drop down list

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
  Select Case Range("State_Selection")
 
  Case "AL"
  Call State_Selection
  Case "CA"
  Call State_Selection
  End Select
End Sub


here is the State_Selection macro code to call

Code:
Sub State_Selection()

 Dim selection As String

  State_Selection = Range("State_Selection")
  
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False

  Sheets("Segmentation").Activate
  ActiveSheet.Unprotect "ops"
  ActiveSheet.Range("SEGMENTATION_TBL").AutoFilter Field:=1, Criteria1:=State_Selection
  ActiveSheet.Protect "ops"
  Range("B6").Activate
  Sheets("Hospital Discharge").Activate
  ActiveSheet.Unprotect "ops"
  ActiveSheet.Range("DISCH_TBL").AutoFilter Field:=10, Criteria1:=State_Selection
  ActiveSheet.Protect "ops"
  Range("B5").Activate
  Sheets("State Selection").Activate
  
  
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
  
 MsgBox "Selected state has been filtered!", vbInformation
  
End Sub

What am I doing wrong? The workbook is attached.

Thanks for your help.
 

Attachments

Back
Top