PDA

View Full Version : Trigger code on cell input



Sir Babydum GBE
08-08-2011, 09:31 AM
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

shrivallabha
08-08-2011, 09:40 AM
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)
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

Sir Babydum GBE
08-08-2011, 11:09 AM
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)
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
That's great, thanks!