ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet change event (https://www.excelbanter.com/excel-programming/277784-worksheet-change-event.html)

Helen Trim[_3_]

Worksheet change event
 
Open the VB editor, and in the Project Explorer, select
the sheet with the calculations. In the Code Window,
paste this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim AddUp As Double
Dim TheRange As Range

Set TheRange = Worksheets("Sheet1").Range("A1:F1")
AddUp = Application.WorksheetFunction.Sum(TheRange)

If AddUp < Range("C8").Value Then
Range("C9").Value = "Wrong"
Else
Range("C9").Value = ""
End If

End Sub

Change the worksheet name and range as needed. This just
puts a message on the sheet, which is less annoying than a
message box popping up continually. If you do want to
catch their attention with a message box, change the if
statement to:

If AddUp < Range("C8").Value Then
MsgBox "The value in C8 should be " & AddUp
End If

HTH
Helen


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com