Macros

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to run a macro automatically after leaving a cell (such as a
lost focus event)?

My test macro is:

Sub Check()
If (Range("c8:c8").Value >= Range("d8:d8") And Range("c8:c8").Value <=
Range("e8:e8")) Then
Range("f8:f8") = "Pass"
Else
Range("f8:f8") = "Fail"
End If
End Sub

Thanks
 
Don't understand if your question is about VBA or getting the result.

To get the result you want use the formula in cell F8 :-
=IF(AND(C8>=D8,C8<=E8),"Pass","Fail")

The correction of your code is :-

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

Sub Check()
If Range("c8").Value >= Range("d8").Value _
And Range("c8").Value <= Range("e8").Value Then
Range("f8").Value = "Pass"
Else
Range("f8").Value = "Fail"
End If
End Sub

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


To get code to run when the cell selection changes it goes into th
worksheetcode module reached via right click sheet tab/click "Vie
Code". Select the event you want to trap from the dropdown box to
right. In this case it will put this into the module for you to ente
code :-


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

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

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

Back
Top