ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatic Macro (https://www.excelbanter.com/excel-programming/288051-automatic-macro.html)

ianripping[_3_]

Automatic Macro
 
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

--
Message posted from http://www.ExcelForum.com


pikus

Automatic Macro
 
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

--
Message posted from http://www.ExcelForum.com


Ron de Bruin

Automatic Macro
 
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

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"ianripping " wrote in message ...
Is it possible to make a macro run the moment a cell has been entered
into?

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

If so whats the code?


---
Message posted from http://www.ExcelForum.com/




pikus

Automatic Macro
 
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

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com