Total Row cell value should not be grater than 4.

poojapradeep406

New Member
Joined
Jan 25, 2019
Messages
1
Hi,
I am trying to write a code where if Total row cell value is more than 4 so it should given an error msg box and restrict the user to do entry.

i am using this code
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private Sub Worksheet_Calculate()
If Range("A1:AS15").Value > 4 Then
MsgBox
"Invalid entry. Enter value in another slot!", vbRetryCancel + vbExclamation
End If
End Sub</code>
Once user do entry in A1:A10 =1 so the total should be 4 only (i mean only 4 entry should allowed).
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Am no VBA expert but try changing this

Code:
If Range("A1:AS15").Value >4Then

to this

Code:
If Application.Sum(Range("A1:AS15")).Value > 4 Then
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,559
Messages
6,125,517
Members
449,236
Latest member
Afua

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