Macro for Data Validation

sucett

Board Regular
Joined
Dec 14, 2007
Messages
122
Hi,

Hope you can help me with this. The Sum of the range A1-A8 should equal 100. Cell A9 contains the formula result. If A9 does not equal 100, i would like to populate a messages to the user stating to please review the entries.

I tried using data validation from excel, but since the A9 contains a formula the message wasn't populated.

Thanks,

:)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This is a macro for the worksheet. Right-click the worksheet tab and choose 'View Code'. Then copy and paste the code below into the white space in the VB editor that opens. Close the editor and save the file.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A8")) Is Nothing Then
    Me.Calculate
    If Range("A9").Value <> 100 Then
        MsgBox "Cell A9 is the sum of cells A1:A8 and must be 100. Please adjust the values in A1:A8 accordingly."
        Application.EnableEvents = False
        Range("A1:A8").Select
        With Target
            .ClearContents
            .Activate
        End With
    End If
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
I must be doing something wrong... VB does not recognize the macro

I modified it as follows:

Private Sub Worksheet()
If Range("a22").Value <> 100 Then
MsgBox "Cell A9 is the sum of cells A1:A8 and must be 100. Please adjust the values in A1:A8 accordingly."
Application.EnableEvents = False
Range("a1:a22").Select
With Target
.ClearContents
.Activate
End With
End If
Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
This is a module for the worksheet itself - NOT a standard module. Follow the instructions in my earlier post to install it. Your modification is not going to work.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top