![]() |
Workbook code vs worksheet code
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 |
Workbook code vs worksheet code
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 wrote in message ups.com... 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 |
Workbook code vs worksheet code
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 wrote in message ups.com... 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 |
All times are GMT +1. The time now is 09:50 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com