DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

How to Run Macro If Any Change Made on Sheet in Specified Range?

In this tutorial, we will guide you on how to run Macro if any change is made on the sheet in specified range using Worksheet. Let’s get them below!! Get an official version of MS Excel from the following link: https://www.microsoft.com/en-in/microsoft-365/excel

The Syntax for the Worksheet Change Event Handler

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("your_range")) Is Nothing Then
      call your_macro
    End If
End Sub

Enter fullscreen mode Exit fullscreen mode

Run a VBA Macro When A change is made in range A2:A100

  • Firstly, in the Excel Worksheet, you have to create sheet 1 and sheet2.
  • Then, you have to go to the Developer Tab.
  • Now, you need to ** ** select the Visual Basic option under the Code section.

Select Visual Basic
Select Visual Basic

  • You have to go to project explorer and double-click on the sheet on which you want to trigger.
  • In sheet2 , you need to copy below code and make changes as per your requirement.
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2:A100")) Is Nothing Then
      Call TestEvent
    End If
End Sub

Enter fullscreen mode Exit fullscreen mode

Copy the Code

  • Then, you have to create module1 and module2.
  • Now, in module2 , you need to copy and paste the following code given below.
 Sub TestEvent()
 MsgBox "Event is working!"
End Sub

Enter fullscreen mode Exit fullscreen mode

Copy the code

  • After that, you need to save the code by selecting it and then close the window.

Save the Code

  • Again, you have to go to the Excel Spreadsheet , and click on the Developer Tab.
  • You need to choose the Macros option in the Code section.

Choose Macro option
Choose Macro option

  • Now, you have to make sure that your macro name is selected and click the *Run * button.

Run the Code

  • Finally, you will receive the output as an Event is Working dialog box in Microsoft Excel.

Output

A Brief Synopsis

Here, we have explained the step-by-step procedure on how to run Macro if any change is made on the sheet in a specified range using Worksheet. Make use of this. Please share your worthwhile feedback in the below comment section. To learn more, check out our website Geek Excel!!

Read Also:

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay