ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Event when a specific cell changes (https://www.excelbanter.com/excel-discussion-misc-queries/200139-event-when-specific-cell-changes.html)

mohavv

Event when a specific cell changes
 
Hi,

I want to run a macro after a specific cell value changes.
Cell A5 has a dropdown menu from which you have to choose one value.
After selecting I'd like a macro to start.

Have tried Event Workbook_Change but I'm doing something wrong because
it reacts on every cell change.

Cheers,

Harold

Dave Peterson

Event when a specific cell changes
 
That workbook_Change event is going to fire each time you make a change to the
worksheet.

But you can get out of the procedure as soon as you realize you're not changing
the cell you want to check.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

if target.cells.count 1 then
exit sub 'only one cell at a time
end if

if intersect(target, me.range("A1")) is nothing then
'get out
exit sub
end if

'code to do real stuff here.
End Sub

To check specific cells:
if intersect(target, me.range("A1,c9,x92")) is nothing then
or
for any cell in column A
if intersect(target, me.range("A:A")) is nothing then

mohavv wrote:

Hi,

I want to run a macro after a specific cell value changes.
Cell A5 has a dropdown menu from which you have to choose one value.
After selecting I'd like a macro to start.

Have tried Event Workbook_Change but I'm doing something wrong because
it reacts on every cell change.

Cheers,

Harold


--

Dave Peterson


All times are GMT +1. The time now is 12:50 PM.

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