Change event macro Question

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
*******************************************
 
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.
*******************************************
 
Back
Top