Automatic Macro

  • Thread starter Thread starter ianripping
  • Start date Start date
I

ianripping

Is it possible to make a macro run the moment a cell has been entere
into?

I know it can be done so the macro runs when you open and close a fil
but can it be done for after a cell has been changed?

If so whats the code
 
Double-click the sheet you're using in your VBAProject to open the cod
window. Paste this in it:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target = Range("A1") Then

End If
End Sub

The code in the If Statement will only run if the particular Range yo
name was the "Target" of the change in the worksheet. - Piku
 
Check out this site about events
http://www.cpearson.com/excel/events.htm

You can use the change event in a Sheet module

Right click on a sheet tab and choose view code
Paste the code there
Alt-Q to go back to Excel

If A1 change the macro "YourMacroName" will run

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Target) Is Nothing Then
YourMacroName
End If
End Sub
 
I do apologize. I meant to put this in the code for the workbook:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target A
Range)
If Target.Column = 1 And Target.Row = 1 Then
MsgBox ("HI!")
End If
End Sub

- Piku
 
Back
Top