Update cell using vba

P

Pete Provencher

Using Excel 2003:

What I would like to do is type a number into a cell and then when I hit
enter I would like vba to update that number through a formula. I know I
could just add another column but if possible I would like to do it the way
mentioned.

Pete Provencher
 
D

Dave Peterson

I'd use the other cell--just because it might make it easier to update the cell
when I make a typing change.

But if you want, rightclick on the worksheet tab that should behave this way.
Select View Code and paste this into the code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then Exit Sub

On Error GoTo ErrHandler:

If IsNumeric(Target.Value) = False Then
Exit Sub
End If

Application.EnableEvents = False
Target.Value = Target.Value * 2 + 3 + Target.Value ^ 4

ErrHandler:
Application.EnableEvents = True

End Sub

I check column A -- you may want to change this.

And I bet my formula isn't what you wanted.
 

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