Can I automate the launch of a macro using the result of a formula

C

Charlie Betz

I have developed a game in Excel. Successful completion causes a formula to
return 'True'. I want this result to launch a macro. As background the macro
will transport the player to another sheet.

Any advice will be very much appreciated
 
P

paul.robinson

Hi
Use the worksheet_change event

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyCell = Range("A1") 'your formula in A1
If not intersect (Target, MyCell) is nothing then 'ignore unless
MyCell changes
If MyCell.Value = 2 then 'value from formula
call myMacro
End if
End if

End Sub

You find this event when you double click the sheet name in the visual
basic editor and choose Worksheet from the dropdown.
regards
Paul
 
D

Don Guillett

Right click sheet tab>view code>paste this. Now if you change cell e1 to 2
you goto sheet 9

Private Sub Worksheet_Change(ByVal Target As Range)
'correct word wrap if necessary
If Target.Address = "$E$1" And Target = 2 Then Sheets("sheet9").Select

End Sub
 

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