Possible to make certain cells default to 0?

K

ktoth04

Hi, so I have a spreadsheet that I use as a timecard, and what I'd like to
do is the following.

I already have data entered in these cells as 0 so that when an employee
does not edit the field, the value is 0. My problem comes when an employee
enters the value in the wrong field. Say an employee means to enter 7 hours
in field N14. He accidentally enters the data in N13, and then deletes the
value, and enters it in N14. However, now instead of 0 in cell N13, there is
no value. What I would like to happen is to have excel automatically make
cells within a specified range default to 0 if they're data is deleted.

Any hints?
 
J

Jim Cone

The following Vba code copied and pasted into the sheet module should
do what you want. I assume you are using the same Excel version that I am.
Alter the range designation..."J1:N25" (two places) to reflect your specific area.
'----
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo SkipTown
Application.EnableEvents = False
If Not Application.Intersect(Target, Me.Range("J1:N25")) Is Nothing Then
Me.Range("J1:N25").SpecialCells(xlCellTypeBlanks).Value = 0
End If
SkipTown:
Application.EnableEvents = True
End Sub
'----
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ktoth04"
wrote in message
Hi, so I have a spreadsheet that I use as a timecard, and what I'd like to
do is the following.
I already have data entered in these cells as 0 so that when an employee
does not edit the field, the value is 0. My problem comes when an employee
enters the value in the wrong field. Say an employee means to enter 7 hours
in field N14. He accidentally enters the data in N13, and then deletes the
value, and enters it in N14. However, now instead of 0 in cell N13, there is
no value. What I would like to happen is to have excel automatically make
cells within a specified range default to 0 if they're data is deleted.
Any hints?
 
G

Gord Dibben

Lock the cells you don't want data entered into then protect the worksheet.


Gord Dibben MS Excel MVP
 
K

ktoth04

It's not that I don't want data entered, its that once they enter the data,
and then delete it, I'd like it to be reset to 0 instead of a blank cell.
 
K

ktoth04

Can I ask a really silly question? What is the sheet module and how do I
access it? Sorry, I don't usually do things this complicated, so I've never
had to access it before...
 
J

Jim Cone

Right-click the worksheet tab, choose "View Code".
Paste the code into the big window on the right side.
On the menu bar click Debug | Compile
On the menu bar click File | Close and Return to Microsoft Excel
The code should now work automatically in the specified range.
Note: you will get a "enable macros?" notice each time the workbook is opened.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ktoth04"
wrote in message
Can I ask a really silly question? What is the sheet module and how do I
access it? Sorry, I don't usually do things this complicated, so I've never
had to access it before...
 
K

ktoth04

Thank you so much!

Jim Cone said:
Right-click the worksheet tab, choose "View Code".
Paste the code into the big window on the right side.
On the menu bar click Debug | Compile
On the menu bar click File | Close and Return to Microsoft Excel
The code should now work automatically in the specified range.
Note: you will get a "enable macros?" notice each time the workbook is opened.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ktoth04"
wrote in message
Can I ask a really silly question? What is the sheet module and how do I
access it? Sorry, I don't usually do things this complicated, so I've never
had to access it before...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top