AUTO ADDITION

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I AM LOOKING FOR A WAY TO HAVE EXCEL AUTOMATICALLY DO
SOME MATH FOR ME. FOR EXAMPLE, IF I TYPE 25 IN CELL B4, I
WANT IT TO AUTOMATICALLY ADD 25 TO IT. ANY THOUGHTS?

THANKS YOU FOR YOUR TIME.
 
Hi
do you want the result in the same cell (that is the value 50 placed in
cell B4?) or is a separate cell sufficient?. for the latter one you can
simply use the formula
=B4+25
placed for example in cell C4

For storing the result in the same cell an event procedure is required
but I would try to use a helper cell. Post back if this is not
sufficient for you
 
I WOULD LIKE TO KEEP IT IN THE SAME CELL IF POSSIBLE. I
HAVE NO IDEA HOW TO DO AN EVENT PROCEDURE. I'M GUESSING BY
HELPER CELL YOU MEAN STORE IT IN ANOTHER CELL?
 
Hi
first: please tun-off your CAPS lock. It's difficult to read and
considered as SHOUTING in newsgroups :-)

To your questions:
1. Helper cell: Yes this would be another cell
2. If you want to have this value in the same cell you have to use VBA.
The following code has to go in your worksheet module:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.count > 1 Then Exit Sub
If Intersect(Target, Me.Range("B4")) Is Nothing Then Exit Sub
On Error GoTo CleanUp:
With Target
if .value <>"" and isnumeric(.value) then
Application.EnableEvents = False
.value = .value +25
End If
End With
CleanUp:
Application.EnableEvents = True
End Sub


For more information about these event procedures take a look at:
http://www.cpearson.com/excel/events.htm
 
Copy the code below, right click on the sheet tab, select view code, and
paste the code in the window that appears. This code will apply your
desired behavior to cells B2:B10, if they are changed one at a time.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myVal As Variant

If Target.Cells.Count > 1 Then Exit Sub

Application.EnableEvents = False
If Not (Intersect(Range("B2:B10"), Target) Is Nothing) Then
myVal = Target.Value
Application.Undo
Target.Value = Target.Value + myVal
End If
Application.EnableEvents = True

End Sub
 
Back
Top