Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
Does anybody know how I can limit a cell with a fromula so that when it comes up with a negative number it resets to 0. I have tried data validation to no avail (it is for input data not output). Any help on this subject would be much appeciated.
Thanks in Advance.

I am not sure if you need the formula to remain in place or not, but this macro I created will check to see if the cell has a formula in it, and if the value of the formula produces a negative result. If the result is negative, then it will reset the cell to 0 (zero). Note: It will replace the formula in the cell with a zero.
Copy and Paste in a new Macro:
___________________________________
Sub del_negatives()
Dim cell As Range
For Each cell In Selection.Cells
If cell.HasFormula And cell.Value < 0 Then
cell.Value = 0
End If
Next
End Sub
______________________________________
Note: You have to manually select your range of cells.
Hope it helps..
GIS_tech.

I don't know what formula or what cell references but let's say:
A1=4
B1=16
and C1 is the cell with your formula of
=A1-B1
(Result is -12)Instead, in C1 use:
=IF(A1-B1<0,0,A1-B1)
Meaning:
If A1 minus B1 is less than zero then zero else A1 minus B1.
(Result is 0)
Note: A1 minus B1 can be any formula you like.HTH
Bryan

![]() |
Outlook images in signitu...
|
Outlook 2003 Newsgroup bu...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |