VBA Code for yes/no pop-up box

MDBHR

New Member
Joined
Sep 17, 2018
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hello,
wondering if I could get some help writing code to create a yes/no pop-up message box?
I want it to appear when I click on a specific sheet within my workbook. Then, depending on the answer, fill a designated cell with an "x".
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Behind your specific sheet module

VBA Code:
Private Sub Worksheet_Activate()
On Error Resume Next
If MsgBox("Want to fill cell?", vbYesNo, "test") = vbYes Then Range(Application.InputBox("Value?", "Test")) = "x"
End Sub
 
Upvote 0
fill a designated cell with an "x"
How do we know what the "designated cell" is?

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
How do we know what the "designated cell" is?

BTW, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
When I click on my "Customer Info" sheet within my workbook, I want the pop-up box to ask, "Has this customer seen our company's digital ad?"
If no, b3="x"
If yes, b2="x"

Thanks! Account details updated.
 

Attachments

  • Screenshot 2021-09-07 141402.png
    Screenshot 2021-09-07 141402.png
    17.6 KB · Views: 22
Upvote 0
Behind your specific sheet module

VBA Code:
Private Sub Worksheet_Activate()
On Error Resume Next
If MsgBox("Want to fill cell?", vbYesNo, "test") = vbYes Then Range(Application.InputBox("Value?", "Test")) = "x"
End Sub
While that code worked perfectly, I'm afraid I didn't explain well enough. If you check out my response to Peter_SSs, it may be more clear to you what my end goal is. VBA Code for yes/no pop-up box
 
Upvote 0
I am not clear on which event you need for your request. You say you want the MessageBox to popup "when [you] click on a specific sheet within my workbook"... does that mean when you first activate (select) the sheet? or does that mean when you click on a cell within the sheet? If the latter, do you everytime any cell is clicked? In any event (no pun intended), here is the line of code that you can use...
VBA Code:
Cells(MsgBox("Want to fill cell?", vbYesNo, "Test") - 4, "B").Value = "X"
 
Last edited:
Upvote 0
Hello,
wondering if I could get some help writing code to create a yes/no pop-up message box?
I want it to appear when I click on a specific sheet within my workbook. Then, depending on the answer, fill a designated cell with an "x".
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    
    Dim Answer As VbMsgBoxResult
  
    On Error Resume Next
    If Sh.Name = "Sheet1" Then
        Answer = MsgBox("Has this customer seen an MDB Ad Online?", vbQuestion + vbYesNo + vbDefaultButton2, "Digital Ad Tracking")

    If Answer = vbYes Then
      Range("B2").Value = ("Dan")
       ElseIf Answer = vbNo Then
      Range("B3").Value = ("Is great")

End If
End If

End Sub
 
Upvote 0
Solution
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
   
    Dim Answer As VbMsgBoxResult
 
    On Error Resume Next
    If Sh.Name = "Sheet1" Then
        Answer = MsgBox("Has this customer seen an MDB Ad Online?", vbQuestion + vbYesNo + vbDefaultButton2, "Digital Ad Tracking")

    If Answer = vbYes Then
      Range("B2").Value = ("Dan")
       ElseIf Answer = vbNo Then
      Range("B3").Value = ("Is great")

End If
End If

End Sub
Written by MrExcel member, Dan Swartz
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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