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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,214,531
Messages
6,120,073
Members
448,943
Latest member
sharmarick

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