autorun macro when a specific cell is altered

Akis7

New Member
Joined
Aug 3, 2005
Messages
15
Is there a way to autorun a macro when a specific cell
for example cell A1<>""?

Thanks
Akis
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
You'd want to either copy the code and include it in a Worksheet_Change() event, or a Worksheet_Calculate() event, or just call the macro from one of those events, if you have other code in them already.

The reason I say either or is because it depends on how the value is being changed. If it's by manual entry, _Change() should work; if by a formula, you'll probably have to end up using _Calculate().

HTH

  • Press Alt-F11 to open the VBE.
    Press Control-R to open the Project Explorer. (May be open already)
    Click "Microsoft Excel Objects" for the file you're working on (should expand the list of the ThisWorkbook module and any sheet modules.)

    For ThisWorkbook and sheet modules:
    Double-click the ThisWorkbook module or the sheet this code applies to.
    Select Workbook, Change or Calculate from the dropdowns.

    Put your code in the right-hand window.
    Press Alt-Q to close the VBE and return to Excel.
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
This runs when any change is made, so need to make specific to cell A1 as shown. Copy/paste to sheet code module (right click tab & "View Code")
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address = "$A$1" Then
        MsgBox ("Cell A1 was changed")
    End If
End Sub
 

Akis7

New Member
Joined
Aug 3, 2005
Messages
15
using the "Worksheet_change()" declaration, it runs the macro when I change any cell in the sheet.

Is there a way to autorun a macro when only cell A1 is changed?
 

joelnichols

Active Member
Joined
Apr 13, 2004
Messages
384
This will run a macro when only A1 is changed. Is that what you wanted or did I miss the idea?
BTW thx for this code. Can't recall who posted it :biggrin:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("a1")) Is Nothing Then

Call "macro name"
End If

End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,056
Messages
5,835,158
Members
430,342
Latest member
Sailingexcel

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
Top