ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet_change event multiple (https://www.excelbanter.com/excel-programming/352963-worksheet_change-event-multiple.html)

jeffP

Worksheet_change event multiple
 
I wanted to test data input on more than one cell. Trying to enter more than
one worksheet_change returns the "ambiguous name" error (same sub name). I
realize that I can do all my IF tests and code calls under the one
Worksheet_change event but it gets crowded.
Is it the only way ?

Thanks for any help and education.
jeffp

John.Greenan

Worksheet_change event multiple
 
You can only habe one worksheet_change event per worksheet. This is the only
way to do it. what you could do is split up the if..elseif..else...end if
from the actual implementation code - something like

Private Sub Worksheet_Change(ByVal Target As Range)

if target.column = 1 then
call DoStuffToColumn1(target)
elseif target.column = 2 then
call DoStuffToColumn2(target)
else
...do whatever
end if

End Sub

private function DoStuffToColumn1(Target as excel.range)
....write code here
end function

private function DoStuffToColumn2(Target as excel.range)
....write code here
end function


--
www.alignment-systems.com


"jeffP" wrote:

I wanted to test data input on more than one cell. Trying to enter more than
one worksheet_change returns the "ambiguous name" error (same sub name). I
realize that I can do all my IF tests and code calls under the one
Worksheet_change event but it gets crowded.
Is it the only way ?

Thanks for any help and education.
jeffp



All times are GMT +1. The time now is 02:48 PM.

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