Data Validation

Brian from Maui

MrExcel MVP
Joined
Feb 16, 2002
Messages
8,459
Aloha,

Is it possible to set a data validtion where that cell has the sum of other cells. I've tried using custom and using the formula to sum cells and greater than, but evertime test it with a value greater than what I want, I get no warning prompt.

:confused:

Brian
 
Hi Brian

If you give me a realistic example I'll set it up so that it's error proof. Nothing worse than a Runtime error for an Excel user.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Dave,

The cells that have the sum formulas are I7 , I8, I12, I16 but they all have different > values, but I can figue that out.

Brian
 
Upvote 0
Here you go

Private Sub Worksheet_Change(ByVal Target As Range)
With WorksheetFunction
If .Sum(Range("I7")) <> 1800 Or _
.Sum(Range("I8")) <> 1800 Or _
.Sum(Range("I12")) <> 1800 Or _
.Sum(Range("I16")) <> 1800 Then

MsgBox "Invalid value", vbCritical
Target.Select
End If
End With
End Sub
 
Upvote 0
Dave,

Never mind I took out the< and just left the > and it works, except the use needs to use the delete key to move on. But that's minor hopefully.

Mahalo for the time and effort and patience.

Brian
This message was edited by Brian from Maui on 2002-03-16 19:47
 
Upvote 0
Hi Brian

You could add:

Application.Undo
Just before the: Target.Select

This would eliminate the need to delete and would return the cell to it's original value


Private Sub Worksheet_Change(ByVal Target As Range)
With WorksheetFunction
If .Sum(Range("I7")) > 1800 Or _
.Sum(Range("I8")) > 1800 Or _
.Sum(Range("I12")) > 1800 Or _
.Sum(Range("I16")) > 1800 Then

MsgBox "Invalid value", vbCritical
Application.EnableEvents = False
Application.Undo
Target.Select
Application.EnableEvents = False
End If
End With
End Sub



And if all these cells should total 1801 each or greater you could use:

Private Sub Worksheet_Change(ByVal Target As Range)
With WorksheetFunction
If .Sum(Range("I7,I8,I12,I16")) > 1800 * 5 Then

MsgBox "Invalid value", vbCritical
Application.EnableEvents = False
Application.Undo
Target.Select
Application.EnableEvents = False
End If
End With
 
Upvote 0
Oops!!! That's because of one of my typos, sorry.

The second part should read:
Application.EnableEvent=True

EG

Private Sub Worksheet_Change(ByVal Target As Range)
With WorksheetFunction
If .Sum(Range("I7,I8,I12,I16")) > 1800 * 5 Then

MsgBox "Invalid value", vbCritical
Application.EnableEvents = False
Application.Undo
Target.Select
Application.EnableEvents = True
End If
End With


To get it running again just place this in a standard Module and run it:

Sub ResetEvents()
Application.EnableEvents=True
End sub
 
Upvote 0
Dave,

I'm sorry, but is my first time doing this, I right click on the tab and copy and paste in the work book,then how do I get to the amn module?

Brian
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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