• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA global sheetchange with excluded sheets

wamaral

New Member
Here is the VBA function I have wrote out currently per each sheet sheet2:sheet21.

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("Input.Trim")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Value > 0 Then Target = Target.Value * -1
End Sub
[/pre]

Is there a way to make this run throughout the entire workbook except a few sheets? Basically, if I change the Input.Trim range for 1 sheet I don't want to have to do it for the 20 other sheets I have. I have made Input.Trim a workbook scope named range instead of an individual sheet named range.


Input.Trim is a named ranged on sheets Sheet2:Sheet21 but not on sheet1. Is there a way to exclude sheet1 from this workbook_change event?
 
In ThisWorkbook Module of the workbook:

[pre]
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name <> "Sheet1" Then
If Intersect(Target, Range("Input.Trim")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Value > 0 Then Target = Target.Value * -1
End If
End Sub
[/pre]

It will run against all sheets except Sheet1. Make sure that you remove individual sheet change events.
 
Back
Top