Occurrence

G

Guest

Guest
I have a worksheet setup and when I add data to the A column, I would like a MsgBox to ask, "Is This An Occurrence?" with YesNo buttons. If the answer is yes, I want to add 1 to the B column, If the answer is no, I don't want it to add anything. Can someone tell me how to write this? I can't get the function to occure without manually running it, and I can get it to enter a 1 in the B column but it does it even when I answer NO!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Put this code in the code for the sheet that you are using (not the module):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Msg, Style, Response
Msg = "Is this an occurfence?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox(Msg, Style)
If Response = vbYes Then
Range("b1") = Range("b1") + 1
End If
End Sub

This code will display a box asking if this "Is an occurrence?" If yes is clicked it will add 1 to the value in cell B1. If no is clicked it will not do anything. The code is activated ANY TIME something on the worksheet changes.

I hope this helps.
Kind regards, Al
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,374
Members
448,888
Latest member
Arle8907

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