VBA to Return Error for a Negative Value


I have a simple excel with multiple worksheets that calculates a running balance on each of the worksheet  using the formula =Max(H7+E8-F8,0). This formula evaluates to zero for every negative result. This is OK but still far from what I need to achieve. 

Is there a VBA or any formula that can help me achieve the same result but this time, compel the user to enter only integers that will result in only positive running balance. If the result (running balance) evaluates to a NEGATIVE value, an ERROR message is thrown back and the operation is reversed. This should be persistent across all the worksheets. 

Thank you. 




You don't need VBA for this, you can use data validation.

Select the 3 cells where the user can input the numbers, I'm assuming H7, E8, and F8 are those cells, and then go to Data Validation (Alt + D + L) > on the Setting tab, select Custom from the Allow drop down menu > Paste the below formula into the text input that appears > uncheck Ignore Blank and hit OK.


If you want to tell the user why there was an error, go to the Error Alert tab in the data validation window and enter a custom message.

This should solve the problem without having to worry about any coding.



Thank you for your kind response. I still get negative running balance when I applied this formula:

However, what I intend to achieve is that once the value of DEBIT entered by the user is greater than the running balance instead of displaying NEGATIVE running balance, I would like for an ERROR to be displayed and if possible, UNDO the operation. Put differently, only POSITIVE running balance is allowed. NEGATIVE balance should be disallowed.
Any help with that?  
Thank you... 
Antong (rep: 2) Feb 25, '18 at 5:54 am
Edit your question and upload a sample file so I can see what you're doing. Then, I'll apply my solution above, if still aplicable, to the workbook.
don (rep: 1287) Feb 25, '18 at 11:45 am
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login