Hi Tom

I have a series of cells: "C21:K21".  They contain numbers.  Using code, is it possible to be able to type a number into a cell, press enter and have the new number added to the one that already existed.  Eg the number 12 is in C21; I type 3 into cell C21 press enter and 15 appears.

If this is possible and is not too timing consuming a task, could you write it for me?

Thanks in advance.



Right click on the sheet tab and select view code.  Put in code like this in the resulting Sheet module:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("C21:K21")
If Target.Count > 1 Then Exit Sub
On Error GoTo Errhandler
If Not Intersect(Target, r) Is Nothing Then
 Application.EnableEvents = False
 v = Target.Value
 On Error GoTo Errhandler
 If IsNumeric(v) Then
    Target.Value = Target.Value + v
    Target.Value = v
 End If
End If
Application.EnableEvents = True
End Sub

Be advised that this will fire each time a cell on the sheet is changed.  

The If statements will keep it from doing anything unless a cell in the range C21:K21 is edited (only one cell).

However, when a macro runs it clears the undo stack - so you will not be able to use undo on this sheet (since the code runs on every edit) and possibly limited use in the workbook.  

If you put in a non-numeric character in a a cell in that range, then it will pretty much stay there.  To clear it. Select at least two cells and clear them both.  

Tested and worked for me as I understand the requirement.

Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 About.com. All rights reserved.