Consulting

Results 1 to 3 of 3

Thread: Trigger code on cell input

  1. #1
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location

    Trigger code on cell input

    Hi

    I would like to have a macro that looks at what information is being input into column K.

    The inputter has a list of things to choose from a validation dropdown. If he chooses "Option3" or "Option4", i need it to execute code that I have written (different code for both options).

    I would later like to be able to add options that might trigger different code lines

    It should do nothing if other options are selected.

    So how do I do it?

    Thanks very much

    BD
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    You can work out like this. This code needs to be put in worksheet module (i.e. right click on the worksheet and then choose worksheet change event)
    [vba]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 11 Then
    Select Case Target.Value
    Case Option3 'Write your option name here
    Call myOption3macro
    Case Option4 'Write your option name here
    Call myOption4macro
    Case Else
    'Do nothing
    End Select
    End If
    End Sub
    Private Sub myOption3macro()
    'macro for option 3 comes here
    End Sub
    Private Sub myOption4macro()
    'macro for option 3 comes here
    End Sub
    [/vba]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Quote Originally Posted by shrivallabha
    You can work out like this. This code needs to be put in worksheet module (i.e. right click on the worksheet and then choose worksheet change event)
    [vba]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 11 Then
    Select Case Target.Value
    Case Option3 'Write your option name here
    Call myOption3macro
    Case Option4 'Write your option name here
    Call myOption4macro
    Case Else
    'Do nothing
    End Select
    End If
    End Sub
    Private Sub myOption3macro()
    'macro for option 3 comes here
    End Sub
    Private Sub myOption4macro()
    'macro for option 3 comes here
    End Sub
    [/vba]
    That's great, thanks!
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •