Worksheet_change not working how i expected

aberenguel

Board Regular
Joined
Aug 10, 2006
Messages
83
Here is the code i'm working with

Private Sub Worksheet_Change(ByVal Target As Range)

Dim trgtCell As Range
Set trgtCell = Range("c22")
If trgtCell.Text = "Use Address from PNCM verb" Then
MsgBox "ANALYST: Confrim Mainframe is coded."
End If

End Sub


The problem i am having is annoying. Once the target cell = "use Address from PNCM verb" the msgbox appears every time any cell on the spreadsheet changes. I want the msgbox to appear only once (whenever the target cell = "Use address from PNCM verb")

any ideas?

thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
L

Legacy 98055

Guest
The code between the "If Then...End If" only runs if the range c22 has actually changed. See the Intesect method in VBA help.

<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> Worksheet_Change(ByVal Target <font color="#0000A0">As</font> Range)

       <font color="#0000A0">If</font> <font color="#0000A0">Not</font> Intersect(Target, Range("c22")) <font color="#0000A0">Is</font> <font color="#0000A0">Nothing</font> <font color="#0000A0">Then</font>
           <font color="#0000A0">If</font> Target.Text = "Use Address from PNCM verb" <font color="#0000A0">Then</font>
               MsgBox "ANALYST: Confrim Mainframe is coded."
           <font color="#0000A0">End</font> <font color="#0000A0">If</font>
       <font color="#0000A0">End</font> <font color="#0000A0">If</font>

  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("105200618428890").value=document.all("105200618428890").value.replace(/<br \/>\s\s/g,"");document.all("105200618428890").value=document.all("105200618428890").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("105200618428890").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="105200618428890" wrap="virtual">
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("c22")) Is Nothing Then
If Target.Text = "Use Address from PNCM verb" Then
MsgBox "ANALYST: Confrim Mainframe is coded."
End If
End If

End Sub</textarea>
 

Forum statistics

Threads
1,136,650
Messages
5,676,996
Members
419,667
Latest member
MegEri

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
Top