View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default 0 (zero) auto delete

Add the two new lines:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("C33:E33")
If Intersect(r, Target) Is Nothing Then Exit Sub
If Target.Value = 0 Then
Application.EnableEvents = False
Target.Clear
Application.EnableEvents = True
End If
End Sub
--
Gary''s Student - gsnu200820


"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.