Change event macro Question

G

Guest

I an analyzing costs on a worksheet. I would like to do a backward
comparison using goal seek.
My input for goal seek is in range "Mygoal"

MyMacro runs fine when i run it from a button after putting my input value
in "Mygoal". code is.
Private Sub myMacro()
Dim myvalue As Integer
myvalue = Worksheets("Cost Sheet").Range("mygoal").Value
Range("MyBillingRate").GoalSeek Goal:=myvalue,
ChangingCell:=Range("MyAccountfactor")
End Sub

I would like to run Mymacro when I "enter" a value into range "Mygoal"
can I do so through the change event? I
 
N

Norman Jones

Hi Martin,

Try:

'============>>
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Me.Range("MyGoal")) Is Nothing Then
Call MyMacro
End If

End Sub
'<<============

This is worksheet event code and should be pasted into the Cost Sheets's
code module (not a standard module and not the workbook's ThisWorkbook
module):

*******************************************
Right-click the worksheet's tab

Select 'View Code' from the menu and paste the code.

Alt-F11 to return to Excel.
*******************************************
 
G

Guest

Perfect thank you Norman
--
Martin


Norman Jones said:
Hi Martin,

Try:

'============>>
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub

If Not Intersect(Target, Me.Range("MyGoal")) Is Nothing Then
Call MyMacro
End If

End Sub
'<<============

This is worksheet event code and should be pasted into the Cost Sheets's
code module (not a standard module and not the workbook's ThisWorkbook
module):

*******************************************
Right-click the worksheet's tab

Select 'View Code' from the menu and paste the code.

Alt-F11 to return to Excel.
*******************************************
 

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