Stop Worksheet Change Macro Triggering When Referenced Data Refreshes But Doesn't Change

JonGil

New Member
Joined
Sep 7, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, I am new to VBA and trying to create a macro that triggers when a value in column A changes. My worksheet data is referenced from another worksheet and set to refresh every day. The problem I am encountering is when the worksheet refreshes even if no changes have occurred my worksheet change macro is triggering. I need it to trigger but only if one of the refreshed values has changed. Is this possible?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim xRgSel As Range
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xMailBody As String
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    Set xRg = Range("A1", Range("A1").End(xlDown))
    Set xRgSel = Intersect(Target, xRg)
    ActiveWorkbook.Save

    If Not xRgSel Is Nothing Then
        MsgBox "Updated"
    End If
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

End Sub
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
66,093
Office Version
  1. 365
Platform
  1. Windows
Thanks Rory.

Never having used that method before, I wasn't sure if it worked like a link (which would not fire it), or if it was like a copy/paste (which would).
Thanks for clarifying!
 

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

NoSparks

Well-known Member
Joined
Mar 15, 2013
Messages
1,477
Office Version
  1. 2010
Platform
  1. Windows
Two questions regarding post #3...

1) Does the message box only appear once ?

2) If you copy the data in column A and paste it as values into a column off to the right, let's say column Z,
does the "triggered by range" remain the same when you refresh or does it now include column Z ?
 

Forum statistics

Threads
1,181,322
Messages
5,929,281
Members
436,660
Latest member
Mouseinalabyrinth

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
Top