How do I add a range to a Worksheet change event?

Certified

Board Regular
Joined
Jan 24, 2012
Messages
189
The following code adds a comment to any cell that has been been change. However, right now it applies to the entire worksheet. Is there a way I can limit the target to a specified range?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


    
    
    
    If Target.Comment Is Nothing Then
    
           Target.AddComment Now & "-" & Target.Value & " -" & Environ("username")
        
    Else
        Target.Comment.Text Now & "-" & Target.Value & " -" & Environ("username")
        
    End If




End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Use INTERSECT to see if the cell you just updated (the "Target" cell) falls in your range. One way to do that is to place this line at the beginning of the code:
Code:
If Intersect(Target, Range("B14:O27")) Is Nothing Then Exit Sub
This will exit the event procedure if your updated cell is not in the specified range. Otherwise, it will continue on and run the code below it.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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