Execute a macro when a cell changes

imported_unknown

Active Member
Joined
Jan 13, 2002
Messages
424
I have a cell in my spreadsheet that contains a link where the value is continually changing. Whenever the value changes I need a macro to automatically execute. How can I achieve this?

thank you
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi J,

You can trap such a change via the use of the worksheet's Calculate event. I assume you do not want to run your macro if the cell is updated, but only if its value changes. If so, here's a sample macro that does this:

Dim LastVal As Variant

Private Sub Worksheet_Calculate()
If LastVal = Empty Then
LastVal = [a1].Value
Else
If [a1].Value <> LastVal Then
Call YourMacro()
LastVal = [a1].Value
End If
End If
End Sub

This example is for cell A1. You must place this code in the worksheet's event code module. To do this, right-click on the worksheet's tab, select View Code, and paste the code into the VBE code pane.
 
Upvote 0
Try this one on the sheet's event page:

Private Sub Worksheet_Change(ByVal Target As Range)
If target = address of the cell you want to keep an eye on Then
Do whatever is is you want done
End if
End Sub

F.T.
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,566
Members
453,053
Latest member
Kiranm13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top