• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run macro on SPECIFIC cell change

ninad7

Member
I have cell A1 (named ObjTotal) which is sum of B1, B3, B5, B7. If A1 is <100 or >100, then I want to have a Message Box telling the user, to change the value of the B1, B3, B5 or B7 such that the sum = 100.


How can I write a VBA for this.


TIA.


Regards,


Ninad.
 
Hi, ninad7!


In the VBA code area of the involved worksheet copy/paste this:


-----

Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)

With Target

If .Column = 2 Then

If .Row = 1 Or .Row = 3 Or .Row = 5 Or .Row = 7 Then

If Range("ObjTotal").Cells(1, 1).Value <> 100 Then

MsgBox "You should enter in B1/B3/B5/B7 values that sum 100. Retry.", _

vbApplicationModal + vbExclamation + vbOKOnly, "Alert"

End If

End If

End If

End With

End Sub

-----


Regards!
 
Back
Top