Trigger event when select from dropdown

前端 未结 2 1300
栀梦
栀梦 2020-12-19 17:31

I need when a user selects an option from the dropdown menu, it will trigger the event and lock down certain range of cells. I got the codes for lockdown cell but I can\'t l

相关标签:
2条回答
  • 2020-12-19 18:07

    an example can be found here with named ranges:

    http://www.sebastianviereck.de/en/VBA-dropdown-change-event-to-perform-action/

    0 讨论(0)
  • 2020-12-19 18:11

    If you're using a data validation dropdown, you can use the Worksheet_Change event like so:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
    
        ' Code to lock ranges goes here
    
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
        End With
    End If
    End Sub
    

    This assumes that your data validation is in cell A1. You'll have to update the reference as appropriate for your situation.

    0 讨论(0)
提交回复
热议问题