#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default 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   Report Post  
Posted to microsoft.public.excel.misc
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
  #5   Report Post  
Posted to microsoft.public.excel.misc
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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto worksheet delete belvy123 Excel Discussion (Misc queries) 3 March 24th 08 12:35 PM
Auto delete gane Excel Worksheet Functions 0 November 27th 07 08:14 AM
Auto delete..... gane New Users to Excel 2 November 21st 07 05:58 AM
Macro auto insert/delete Eric Excel Discussion (Misc queries) 3 June 12th 07 09:09 PM
how to delete an auto footer Dool Excel Discussion (Misc queries) 4 June 10th 05 01:19 PM


All times are GMT +1. The time now is 03:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"