VBA code to activate a macro when cell is activated?


  • This goes in the sheet module as opposed to a standard module


    HTH

    <a href="http://www.mrexcel.com/relayforlife.shtml" target="new"><img src="http://www.myimgs.com/data/vonpookie/anne_relay.gif"></a>

  • Hi ToBe,


    A shorter version of Iridium's approach:


    Option Explicit


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set Target = Me.Range("A2")


    If Not Intersect(ActiveCell, Target) Is Nothing Then
    MsgBox "Hello Finland - I hop everything is OK with You!"
    End If
    End Sub


    Kind regards,
    Dennis

  • Excellent, All OK in Finland - as it just today started to snowing and the weather changed back to normal Finish winter like. Hope you got some of it also in Sweden. :)


    Dennis, your code works just perfect - so it will lounch the macro after cell activating, but for some reason Iridiums code works only for cell change (?)


    Thank you for you both,


    Br, ToBe

  • Hi ToBe,


    Yes - we got snow and also coldness
    :yes:


    AS You may note Iridium use the event WorkSheet_Change while I use the event WorkSheet_SelectionChange. This explain the different output You get.


    Take care and I hope You enjoy the winter :)


    Kind regards,
    Dennis

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!