ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looking for Cell_Change Event (https://www.excelbanter.com/excel-programming/278521-looking-cell_change-event.html)

Mike[_53_]

Looking for Cell_Change Event
 
I have a worksheet that has several cells that users will
change. I am currently using the Private Sub
Worksheet_Change() function to activate the code. This
function runs the code anytime ANY CELL is modified.

I'm looking for a similar event funtion that only runs the
code when a certain cell is modified.

For instance, when A1 is changed I want the function Name
() to run. When A2 is changed I want the function Group()
to run. However, I don't want Name() to run when A2 is
changed or Group() to run when A1 is changed as would
happen using Worksheet_Change().

Any suggestions???

Jake Marx[_3_]

Looking for Cell_Change Event
 
Hi Mike,

You're kind of out of luck with that, as there are no more specific Change
events. However, you can do a simple check in the Worksheet_Change event to
see which cell has changed:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, _
Range("A1")) Is Nothing Then
MsgBox "A1"
End If
If Not Application.Intersect(Target, _
Range("A2")) Is Nothing Then
MsgBox "A2"
End If
End Sub

The argument "Target" will contain a reference to the Range object that was
changed. This should execute pretty quickly, so I doubt you'll notice any
slowing due to it.

--
Regards,

Jake Marx
www.longhead.com


Mike wrote:
I have a worksheet that has several cells that users will
change. I am currently using the Private Sub
Worksheet_Change() function to activate the code. This
function runs the code anytime ANY CELL is modified.

I'm looking for a similar event funtion that only runs the
code when a certain cell is modified.

For instance, when A1 is changed I want the function Name
() to run. When A2 is changed I want the function Group()
to run. However, I don't want Name() to run when A2 is
changed or Group() to run when A1 is changed as would
happen using Worksheet_Change().

Any suggestions???




All times are GMT +1. The time now is 06:05 PM.

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