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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
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>
 

RsLewis

New Member
Joined
Apr 21, 2002
Messages
14
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
 

Forum statistics

Threads
1,144,766
Messages
5,726,170
Members
422,659
Latest member
RGP268

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
Top