Workbook code vs worksheet code

  • Thread starter Thread starter dean.brunne
  • Start date Start date
D

dean.brunne

Hi-This code works when in This Workbook section for code but I want
to have it work in one worksheet only. I tried just copying the code
the the specifc worksheet. Didn't work. What do I change?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
Target.Interior.Color = vbRed
End Sub
 
Dean,
With events that are built-in to the object in Excel or those you define,
you will find it more reliable to get VBA to generate the stubs for you,
thereby guaranteeing that the signature, arguments etc are correct.
In the WS module that you wish to add the code, go to the top-left combo box
and select "WorkSheet". Then in the top-right combo box, select the event
you want, in this case "Change".

Now add your desired code in the routine.

NickHK
 
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name <> "LastOne" Then End
Target.Interior.Color = vbRed
End Sub

Change the sheet name to the one you want this to run.


Regards
Robert McCurdy
Hi-This code works when in This Workbook section for code but I want
to have it work in one worksheet only. I tried just copying the code
the the specifc worksheet. Didn't work. What do I change?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
Target.Interior.Color = vbRed
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top