Ignore Click Event

keith0528

Active Member
Joined
Apr 23, 2009
Messages
250
Greetings All,

I have some nifty code that tracks user changes (think i got it from this forum) anyway, I'm only wanting to pick up manual changes made to the worksheet(s). I want it to ignore click events. I don't want to track any cmd button pushes. This results in data collection overload. Here is the track_changes code:


Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


ActiveWorkbook.Sheets("TrackChanges_Record").Visible = xlSheetVeryHidden


If ActiveSheet.Name = "TrackChanges_Record" Then Exit Sub


Application.EnableEvents = False


On Error Resume Next


UserName = Environ("USERNAME")


NewVal = Target.Value


Application.Undo


oldVal = Target.Value


lr = Sheets("TrackChanges_Record").Range("A" & Rows.Count).End(xlUp).Row + 1


Sheets("TrackChanges_Record").Range("A" & lr) = Now
Sheets("TrackChanges_Record").Range("B" & lr) = ActiveSheet.Name
Sheets("TrackChanges_Record").Range("C" & lr) = Target.Address
Sheets("TrackChanges_Record").Range("D" & lr) = oldVal
Sheets("TrackChanges_Record").Range("E" & lr) = NewVal
Sheets("TrackChanges_Record").Range("F" & lr) = UserName


Target = NewVal


Application.EnableEvents = True
End Sub

thanks in advance
 

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 Keith,

Clicking a button won't directly trigger the Workbook_SheetChange event. You probably have some actions in the code associated with the button, that is causing a Change to the workbook cells. Those statements are the ones that are actually triggering the Workbook_SheetChange event.

To prevent that, you can temporarily disable events like this...

Code:
Private Sub CommandButton1_Click()
   Application.EnableEvents = False
   Range("A1").Value = "NewValue"
   Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,218,620
Messages
6,143,518
Members
450,492
Latest member
Rusbus1972

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