Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
eddied
 
Posts: n/a
Default Ways to activate a macro

Is there a way to cause a macro to execute when a certain cell is exited? My
end goal is described in an additional post: How can I force certain text
formatting in a cell?
  #2   Report Post  
Oliver Ferns via OfficeKB.com
 
Posts: n/a
Default

Yes....set up a private global variable in sheet code like this

Private strLastCell As String

Then use this code (changing "$A$1" to whatever cell you want).....

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If strLastCell = "$A$1" Then
Call yourmacroname
End If
Let strLastCell = Target.Address
End Sub


This won't work the first time you exit the cell as the global variable is
set after the code has run so you need to add this code as well (replacing
"$A$1" again...

Private Sub Worksheet_Activate()
Let strLastCell = "$A$1"
End Sub



Having said all this, I cannot think of a situation where this is useful,
but hey!

Hope this helps...
Oli

--
Message posted via http://www.officekb.com
  #3   Report Post  
Oliver Ferns via OfficeKB.com
 
Posts: n/a
Default

Hi,
the Worksheet Activate event code should read this...

Private Sub Worksheet_Activate()
Let strLastCell = ActiveCell.Address
End Sub

otherwise the code will fire from the first cell you "exit"
Cheers,
O

--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Help with macro formula and variable Huge project Excel Worksheet Functions 0 December 28th 04 01:27 AM
Executing macro for all worksheet from a different worksheet Biti New Users to Excel 3 December 8th 04 10:05 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 08:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"