MrExcel Publishing
Your One Stop for Excel Tips & Solutions

macro runned when certain cells are changed


Posted by Pasi Vartiainen on March 06, 2001 4:26 AM

I want to make my macro run every time when cell B4 or B5 value is chanced. Is there some private sub attatced to sheet which allows me to do this. Private Sub Workbook_change () is not good, because it activates macro every time when something is changed in sheet. So, my problem is what is the name of this kind of procedure?

I Hope that someone can help...
Pasi Vartiainen


Posted by Dave Hawley on March 06, 2001 5:38 AM


Hi Pasi

Each sheet in a workbook has it's own module that is triggered by Events. To access them, right click on the sheet name tab and select "View Code".

Here is some code that will fire only if cell B4 or B5 changes.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$B$4" Or Target.Address = "$B$5" Then
'Your Macro
End If
End Sub


Dave

OzGrid Business Applications