ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Zero Default (https://www.excelbanter.com/excel-programming/379073-re-zero-default.html)

Dave Peterson

Zero Default
 
Not as a default, but you could use an event macro that looks at the cell after
the change and if it's empty, it changes the cell to 0.

If you want to try, right click on the worksheet tab that should have that
behavior and select view code. Paste this into the code window that just
opened:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myCell As Range
Dim myRng As Range

Set myRng = Me.Range("a1:b99") 'whatever range should be checked

If Intersect(Target, myRng) Is Nothing Then Exit Sub

On Error Resume Next
Application.EnableEvents = False
For Each myCell In Intersect(Target, myRng).Cells
If myCell.Value = "" Then
myCell.Value = 0
End If
Next myCell
Application.EnableEvents = True
On Error GoTo 0

End Sub


Macros have to be enabled for this to work. And change the range (I used
A1:B99) to what you need.

Please help James wrote:

Is there any way that I can make each cell a zero default, so that whenever a
number is deleted within a cell, it reverts back to zero. Thanks!


--

Dave Peterson


All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com