Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger macro from cell change?

Status
Not open for further replies.

MatthewP

Programmer
Jan 16, 2001
176
GB
Does anyone know if it's possible to trigger a macro from a cell changing value in Excel, in the same way that a formula works? Or can I write a formula that runs a macro?

Thanks,
Matt.
 
Dump the macro code into the
Code:
Worksheet_Change
event of the sheet you're working on. To do this, go to the VBA editor (ALT+F11 from within Excel) find the worksheet in the Project Explorer window, right-click it and select View Code. There will be two dropdown menus at the top of the screen. Select
Code:
Worksheet
from the left one, and
Code:
Change
from the right one.
 
you can limit which cell call you macro with the following snippet (this trapps the first 9 rows by 5 columns>:-

If ((ActiveCell.Row > 1) And (ActiveCell.Row < 9)) Then
' MsgBox (&quot;Trapped Row &quot; & (ActiveCell.Row))
If ((ActiveCell.Column > 1) And (ActiveCell.Column < 5)) Then
' MsgBox (&quot;Trapped Column &quot; & (ActiveCell.Column))
Call Sort_table
End If

End If

Martin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top