ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On change event for specific cells (https://www.excelbanter.com/excel-programming/400445-change-event-specific-cells.html)

headly

On change event for specific cells
 
I am familiar with the worksheet on change event, but can I use it to narrow
down so that the code runs only based on changes to a specific range of
cells, not knowing beforehand what the current value of any of those cells
are, only if the value in the cells in a specific range is changed? TIA

Jim Thomlinson

On change event for specific cells
 
Two ways. The change event has an argument Target. That is the cell or cells
that were changed. So based on that...

if target.address = "$A$1" then
msgbox target.address
end if

'**or**

if not intersect(target, range("A1:B10")) is nothing then
msgbox target.address
end if

if the cell that you wnat to detect a chnge in is a formula then that gets a
bit trickier but it can still be done. Reply back if that is the case...
--
HTH...

Jim Thomlinson


"headly" wrote:

I am familiar with the worksheet on change event, but can I use it to narrow
down so that the code runs only based on changes to a specific range of
cells, not knowing beforehand what the current value of any of those cells
are, only if the value in the cells in a specific range is changed? TIA


Incidental

On change event for specific cells
 
hi there

a way to do it would be to use intersect

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A10")) Is Nothing Then

MsgBox "I am part of your set range"

Else

MsgBox "Where as i am not"

End If

End Sub

hope it helps

S




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

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