View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default 0 (zero) auto delete

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then
Exit Sub 'one cell at a time
End If

If Intersect(Target, Me.Range("C33:E33")) Is Nothing Then
Exit Sub
End If

If Target.Value = 0 Then
Application.EnableEvents = False
Target.ClearContents 'save the formatting
Application.EnableEvents = True
End If
End Sub


Ben in CA wrote:

Thank you very much for the quick reply!

Is there a way I can set this to only do it for a certain range or cell -
instead of the whole worksheet?

E.g. - only for the cells C33 - E33

Ben

"Gary''s Student" wrote:

Put this event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = 0 Then
Application.EnableEvents = False
Target.Clear
Application.EnableEvents = True
End If
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200820


"Ben in CA" wrote:

Hi,

Is there any way that I can set a cell to automatically empty (delete the 0)
if someone enters a zero in the cell?

(Preferably with a macro)

(It's not for use by myself - I'd just hit the delete key instead of 0.)

Thanks for any suggestions.


--

Dave Peterson