Unsuccessful Worksheet.Change with Target Range

Nadine67

Board Regular
Joined
May 27, 2015
Messages
225
Hello and thank you for any attention my post may receive.

I have a worksheet that has one target range (P3:P500) containing formulas where if the cell in this column on the active row calculates to 3 then a message box will appear so that the user can decide to either cancel, or OK to execute further code. All instances of 0 on non-active rows is ignored.

Example -
if row 3 is the active row and P3 = 0 the a message box will appear.
MNOP
36/6/18YesApple=COUNTIF(M3:O3,"")
47/6/18Yes =COUNTIF(M4:O4,"")
5YesOrange=COUNTIF(M5:O5,"")
to 500

<tbody>
</tbody>

I am confused as to what code I need to execute to successfully achieve my goal. I used this code (unsuccessfully) which I found on the net but do not know how to tweak it to look at only the 'P'-cell in the active row.

Code:
Private Sub Worksheet_Calculate()
Static oldval
If Range("P3").Value = 0 Then
    oldval = Range("P3").Value
    If MsgBox("You have entered information in all three mandatory fields." _
    & vbNewLine & vbNewLine & "If you are sure the information is correct and would like to close this Action, please select 'OK'." _
    & vbNewLine & vbNewLine & "Otherwise select 'Cancel' to keep this Action open; by the way this will clear the 'Closure Date' field.", vbOKCancel) = vbCancel Then Range("M3").ClearContents
End If
End Sub

Any help will be greatly appreciated.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
See if this does what you want. I took out the "oldvalue" line for testing purposes, and because you didn't use it (at least in this routine). If you're using it elsewhere, add it back in....

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M3:O500")) Is Nothing Then
    If Range("P" & Target.Row).Value = 0 Then
        If MsgBox("You have entered information in all three mandatory fields." _
        & vbNewLine & vbNewLine & "If you are sure the information is correct and would like to close this Action, please select 'OK'." _
        & vbNewLine & vbNewLine & "Otherwise select 'Cancel' to keep this Action open; by the way this will clear the 'Closure Date' field.", vbOKCancel) = vbCancel Then Range("M" & Target.Row & ":O" & Target.Row).ClearContents
    End If
End If
End Sub
 
Upvote 0
**** SOLVED ****

Thank you jproffer. Your solution has solved my issue and reached my goal.

Have a great day!
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,027
Members
449,414
Latest member
sameri

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