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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,330
Messages
5,571,570
Members
412,406
Latest member
DutchMonkey
Top