Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
0 (zero) auto delete
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. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
0 (zero) auto delete
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. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
0 (zero) auto delete
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. |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Auto worksheet delete | Excel Discussion (Misc queries) | |||
Auto delete | Excel Worksheet Functions | |||
Auto delete..... | New Users to Excel | |||
Macro auto insert/delete | Excel Discussion (Misc queries) | |||
how to delete an auto footer | Excel Discussion (Misc queries) |