![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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!
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|