Execute code by changing a Cell

  • Thread starter Thread starter gatarossi
  • Start date Start date
G

gatarossi

Dear all,

I need that excel execute some VBA code when I change the value of a
cell in a sheet...

How can I do it?

Thanks a lot !!!

André.
 
right click sheet tab>view code>left window select worksheet>right window
select worksheet_change
write code. You probably will want to restrict to a cell or range.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Dear all,

I need that excel execute some VBA code when I change the value of a
cell in a sheet...

How can I do it?

Thanks a lot !!!

André.
 
Dear Don Guillett,

If I want that the code execute when I change a cell, how can I do it?

And If I have more than one cell? For example, If when I change
cells(1,1) do it...
and when I change cells (2,1) do another code...

Thanks a lot!!!

André.
 
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then MsgBox "High"
If Target.Address = "$A$2" Then MsgBox "Low"
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Dear Don Guillett,

If I want that the code execute when I change a cell, how can I do it?

And If I have more than one cell? For example, If when I change
cells(1,1) do it...
and when I change cells (2,1) do another code...

Thanks a lot!!!

André.
 
André,

Roger has given you the code to cause your code to run when a particular cell has been
changed. If it's a range of cells, like an entire column, here's an oft-used technique:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect( Target, Range("A:A")) is Nothing then
' your code here
End If
End Sub
--
Earl Kiosterud
www.smokeylake.com

Note: Top-posting has been the norm here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
Dear all,

I need that excel execute some VBA code when I change the value of a
cell in a sheet...

How can I do it?

Thanks a lot !!!

André.
 
Here's one I got from Mudraker awhile back that will run a different macro
depending on the value entered in A2

Private Sub Worksheet_Change(ByVal Target As Range)
'By Mudraker 3/26/06
If Target.Address = "$A$2" Then
Application.EnableEvents = False
Select Case Target.Value
Case "Purchase"
Call macroA
Case "Sales"
Call MacroB
End Select
End If
Application.EnableEvents = True
End Sub

Vaya con Dios,
Chuck, CABGx3
 
Back
Top