ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Launch a Sub Worksheet_Change Event from inside a macro (https://www.excelbanter.com/excel-programming/281953-launch-sub-worksheet_change-event-inside-macro.html)

Rolo[_3_]

Launch a Sub Worksheet_Change Event from inside a macro
 
Hi all, thank you for your help.

Is it possible to launch the Sub Worksheet_Change Event from inside a macro?

I tried this but It doesn´t work

Sub Macro 1()
Sub Worksheet_Change Event
(rest of the code)
end sub

Thanks !

Chip Pearson

Launch a Sub Worksheet_Change Event from inside a macro
 
Rolo,

You can call the Worksheet_Change event procedure from another sub in a
standard code module. First, change the Private keyword to Public, then
call the sub with code like

Sheet1.Worksheet_Change Range("A1")

Change "Sheet1" to the VBA codename (not the worksheet name) of the
appropriate sheet.

A better, more structured, way is to put the code that currently resides in
Worksheet_Change in another procedure in a standard code module and call
that procedure. E.g,.

[in a standard code module]
Sub DoSomething (ByVal Target As Range)
' whatever
End Sub

[in the sheet module]
Public Sub Worksheet_Change(ByVal Target As Excel.Range)
DoSomething Target:=Target
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Rolo" wrote in message
om...
Hi all, thank you for your help.

Is it possible to launch the Sub Worksheet_Change Event from inside a

macro?

I tried this but It doesn´t work

Sub Macro 1()
Sub Worksheet_Change Event
(rest of the code)
end sub

Thanks !





All times are GMT +1. The time now is 01:52 PM.

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