A ali zaib New Member Jan 3, 2011 #1 run macro when we left the cell suppose i have select a2 when i press enter or down key then run macro
run macro when we left the cell suppose i have select a2 when i press enter or down key then run macro
X xld Member Jan 3, 2011 #2 [pre] Private prevCell As Range Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not prevCell Is Nothing Then If prevCell.Address = "$A$2" Then Call myMacro End If End If Set prevCell = Target End Sub [/pre] This is worksheet event code. To implement it, select the sheet tab, right click, and select View Code. Paste this code into the code module that opens in the VBIDE. Then close the VBIDE and test it in Excel.
[pre] Private prevCell As Range Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not prevCell Is Nothing Then If prevCell.Address = "$A$2" Then Call myMacro End If End If Set prevCell = Target End Sub [/pre] This is worksheet event code. To implement it, select the sheet tab, right click, and select View Code. Paste this code into the code module that opens in the VBIDE. Then close the VBIDE and test it in Excel.