DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

How to Change Event To Run Macro When any Change is Made using Worksheet?

In this tutorial, we will guide you on how to change events to Run Macro when any change is made 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)
'your code
'
'
End Sub

Enter fullscreen mode Exit fullscreen mode
  • Firstly, in the Excel Worksheet, you have to go to the Developer Tab.
  • Then, you need to ** ** select the Visual Basic option under the Code section.

Select Visual Basics

  • Now, you have to copy and paste the following code.
 Private Sub worksheet_change(ByVal Target As Range)
 Msgbox "You updated something in this sheet"
End Sub

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

Save the Code

  • Now, if you have this code on sheet1, and you write or delete something in the sheet1 , the message will pop that “You updated something in this sheet”.

Run Excel Macro if Any Change is Made on Worksheet

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

Select Visual Basics

  • Now, you have to go to project explorer and double-click on the sheet on which you want to trigger the worksheet.change event.
  • Then, you have to put your code in this segment and call my subroutine that is in a module. So I simply call that subroutine in this worksheet event handler. My subroutine is FormatUsingVBA() in Module1.
  • You need to copy and paste the code given below.
 Private Sub worksheet_change(ByVal Target As Range)
 Call FormatUsingVBA
End Sub

Enter fullscreen mode Exit fullscreen mode
  • 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

  • Now, you have to make sure that your macro name is selected and click the *Run * button.
  • Finally, you will get *output * as given below in the Excel.

A Brief Synopsis

Here, we have explained the step-by-step procedure on how to change events to Run Macro when any change is made 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:

Top comments (0)