I would like to add a YES NO message before executing my code. YES to continue and NO to…
- User
I would like to add a YES NO message before executing my code. YES to continue and NO to exit Sub. Can you please show me how to do it
- Assistant
Sure! Here's an example of how you can add a YES/NO message box before executing your code in VBA:
vbaSub YourSubroutineName() ' Display a message box with Yes/No buttons Dim answer As VbMsgBoxResult answer = MsgBox("Do you want to continue?", vbQuestion + vbYesNo, "Confirmation") ' Check the user's response If answer = vbYes Then ' Execute your code here MsgBox "Your code is executing..." ' Rest of your code goes here ' Display a confirmation message MsgBox "Your code executed successfully." Else ' User clicked No, exit the Sub MsgBox "Code execution cancelled." Exit Sub End If End SubIn this example, a message box is displayed with the question "Do you want to continue?" and Yes/No buttons. If the user clicks Yes, the code between the "Execute your code here" and "Rest of your code goes here" comments will be executed. If the user clicks No, a cancellation message is displayed, and the Sub is exited using .
- User
When my sheet activates, I want a YES NO message that will say' "HAVE YOU PRINTED ALL STAFF SCHEDULE SHEETS FOR TODAY?"
- line break twice - "Do not update this sheet until you have done so" If I answer YES, Then I do not want the message to appear until the next day. If I answer NO, The message should appear the next time I activate the sheet.
I also have a Button to Update the page that runs the VBA code below; Sub TaskBackUp() Dim today As String ' Clear Yesterdays recorded Tasks once a day today = Format(Now, "ddd") If today <> "Sat" And today <> "Sun" Then If Range("B1").Value <> Date Then Dim wb As Workbook Set wb = ThisWorkbook Dim sourceRange As Range Set sourceRange = wb.Worksheets("Daily").Range("N7:T11") Dim archiveSheet As Worksheet Set archiveSheet = wb.Worksheets("Archive") Dim nextRow As Long nextRow = archiveSheet.Cells(archiveSheet.Rows.Count, "A").End(xlUp).Row + 1 archiveSheet.Range("A" & nextRow & ":G" & (nextRow + 4)).Value = sourceRange.Value Range("B1").Value = Date End If Application.Wait Now + TimeValue("00:00:01") End If Call ClearEntry End Sub
I want the same message in the event 'Sub TaskBackUp() that will do the same thing, If I answer YES, Then I do not want the message to appear until the next day. If I answer NO, The message should appear the next time I click on the button.
- Assistant
- User
I only want this condition to activate for sheet 'Daily'. And does the entire code go into one module?
- Assistant
- User
I have an error'Sub or Function not defined' on the line 'ShouldShowMessage' in the event 'Sub TaskBackUp()'
- Assistant