Worksheet_Change Question

RsLewis

New Member
Joined
Apr 21, 2002
Messages
14
Excel file 1 has worksheet code as follows:Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column > 1 And Target.Column < 15 Then
Cells(Target.Row, 16) = True
End If

End Sub
I want to, in a macro, open another file, and set the worksheet code to this same sub.
How do I do it?
Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi RsLewis,
If you want to use this event for all xl files, you need to use class module(as application event).

<Pre>
'//Put this code on Class Module named Class1 on Personal.xls
Public WithEvents App As Application

Private Sub App_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column > 1 And Target.Column < 15 Then
Cells(Target.Row, 16) = True
End If
End Sub


'//Put this code on Std Module named on Personal.xls
Public x As New Class1

Sub Auto_Open()
Set x.App = Application
End Sub
</Pre>
 
Upvote 0
Colo,
Thanks for that info. If I don't want to do this for all excel files, but only ones I create thru a specific macro, does your answer change?
Thanks, Bob
 
Upvote 0

Forum statistics

Threads
1,215,267
Messages
6,123,964
Members
449,137
Latest member
yeti1016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top