In this article, we will use change event of worksheets to display a warning message when the column total exceeds total value.
Raw data consists of salt composition of a medicine. It comprises of salt name and it's weight per 10 grams.
Total of all the salt ingredients is equal to 10 grams. When we change the weight of ethane salt from 0.75 to 1, a warning message will pop-up.
In this article, we have used change event of worksheet to generate warning message. Change event checks the total of 2nd column, which should not exceed 10.
If Target.Column = 2 Then
The above code is used to restrict change event to trigger only when value in the 2nd column is changed.
The above code is used to get sum of all the values in column 2.
Please follow below for the code
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) 'Checking whether value is changed in second column If Target.Column = 2 Then 'Checking whether sum of values in second column is greater than 10 If WorksheetFunction.Sum(Columns(2)) > 10 Then MsgBox "Caution, Total has exceeded 10g" End If End If End Sub
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at firstname.lastname@example.org
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.