macro not working if formula bar is used

  • I have a piece of code as follows


    Code
    If Range("FY05_deducuction_percentage").Value < 0.95 Then
        MsgBox "FY06 percentage has dropped below 95% of FY05 budget" & vbCrLf & "Please adjust the last figure entered!!!", _
        vbExclamation, "Please edit the last number"
        Application.Undo


    it works fine,, until somebody enters values in the formula bar, then the macro won't notice the value is less than 95%.. How can this be corrected? Thanks!

  • Re: macro not working if formula bar is used


    Hi jjst34,


    Need more info.


    Is your code activated by a control or an event. Normally no code runs while the user is entering data in the formula bar. After the user hits enter or selects a cell with the mouse then any event driving code will run.


    An exception is the KeyUp or KeyDown events and some of the mouse events.


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: macro not working if formula bar is used


    Thanks for the reply.. Hope this is helpful


    Private Sub worksheet_change(ByVal Target As Excel.Range)


    I'm assuming there is a different/better way to activate it? Thanks!

  • Re: macro not working if formula bar is used


    just an update.. I tried using the following:


    Private Sub worksheet_change(ByVal Target As Excel.Range)
    If Range("FY05_deducuction_percentage").Value < 0.95 Then
    MsgBox "FY06 percentage has dropped below 95% of FY05 budget" & vbCrLf & "Please adjust the last figure entered!!!", _
    vbExclamation, "Please edit the last number"
    Application.Undo


    but now I can change a figure, it will go below 95%, and won't give a message until I move the selection. which sounds fine,, but now if I just change something and then hit close, save. It allows the change, then next time the sheet is opened, the message comes up, but it can no longer undo the change.. Any ideas?? Thanks!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!