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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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.
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,289
Members
448,885
Latest member
LokiSonic

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