Pressing "Enter" to run macro

  • Thread starter Thread starter grin2000
  • Start date Start date
G

grin2000

I have an imput box in cell F5. The only things that can be imputte
inside that cell is a dollar amount.

I want a macro to run only after someone has entered a number in tha
cell and right after he/she imputs the amount and presses Enter.

Can this be done in this manner or will I still need to place a butto
next to the cell to click once an amount has been imputted?

Thanks, I appreciate the help
 
even better. It can be automatic
right click sheet tab>view code>copy/paste this. Change cell to suit. Use A
instead of a.

Private Sub Worksheet_Change(ByVal Target As Range)
if target.address="$A$1" then call mymacro
End Sub
 
I tried it and it gives my

"Compile error:
Sub or Function not defined"

the cell is f73 that I want to run so I put $F$73 but it gives me thi
erro
 
Grin,

what you probably did is copy the exact code Don gave you. When cel
F73 changes it calls the Sub "mymacro", which Don put in the code as a
example of a Sub to run if the cell has changed.

I don't know what you want to happen when the cell changes, but you ca
approach it in two ways. The first is to put the code right in th
Worksheet_Change event. The second is to call another Sub when the cel
changes:

FIRST:

Code
-------------------

Private Sub Worksheet_Change(ByVal Target As Range)

If target.address="$F$73" then
'Write whatever code is needed, for example:
MsgBox ("Cell F73 has changed to value: " & Target.Value)
end if

End Sub

-------------------

SECOND:

Code
-------------------

Private Sub Worksheet_Change(ByVal Target As Range)

if target.address="$F$73" then
call GrinsMacro(Target)
end if

End Sub


Sub GrinsMacro(Target As Range)

'Write whatever code is needed, for example:
MsgBox ("Cell F73 has changed to value: " & Target.Value)

End Sub
 
This goes into the code module for the sheet (right click tab & Vie
Cose).

'-------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$F$5" Then
MsgBox ("Put code here.")
End If
End Sub
'-----------------------------------------------------
 
grin2000 > said:
no it's called Test and I did change it to that but it still gives me
that error

Test should be in the same module or in a standard module. If it's in
another sheet module then it must be addressed like this:

Call Sheet2.Test

HTH. Best wishes Harald
 
Back
Top