Macro Misfiring

jrarmstrong

Board Regular
Joined
Mar 15, 2010
Messages
202
Hi,


I am trying to put together a macro to automatically trigger a message box when the result of a formula is the word “Five”.


I have a small table B3:C13. In the B column a user enters text and the adjacent C column contains a VLOOKUP formula that inserts the word “Five” into column C if the criteria of the formula is met.


I have used the code below but this triggers when the text is entered into column B rather than when the criteria of the formula is met. Text will be entered in the morning and the formula looks up a range in another sheet where the data is imported periodically from an external source during the day. The message box should only fire when criteria is met.


Can anyone shed any light on what I am doing wrong?


Thanks,


James



Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)


    If Target.Cells.Count > 1 Then Exit Sub


    If Not Intersect(Target, Range("B3:C13")) Is Nothing Then


        If Target.Offset(, 1).Value = "In Play" Then


            MsgBox "Already used"


        End If


    End If


End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
.
.

Rather than using a Worksheet_Change event, you need to use a Worksheet_Calculate event.

(First, you'll need to make sure your Excel is set to automatic calculation mode.)

Try this code:

Code:
Private Sub Worksheet_Calculate()

    Dim Cell As Range

    For Each Cell In Me.Range("C3:C13")
        
        If LCase(Cell.Value) = "five" Then
            '
            '
            'more code goes here
            '
            '
        End If
    
    Next Cell

End Sub
 
Upvote 0
Hi,

Thanks for this. It does not seem to trigger however. I have added in MsgBox "Five" and checked that automatic calc in on.

James
 
Upvote 0
.
.

It should work fine.

Make sure you place the macro in the code module for that particular worksheet (and not in the worksheet containing your "lookup" range) and delete the existing Worksheet_Change sub procedure...
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,931
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top