Question & Answer: In Microsoft VBA do the following:…..

In Microsoft VBA do the following:

Add a new worksheet in the ned, assign code name =wsEX6

tab name = EX3_1_6

Use MsgBox

Display the button “Yes”, “No”, and “Cancel”

Write the message “Are you awake?”

Display the question mark,

Capture the response in the integer variable intR, put intR value in cell A2

a. if the response is Yes, then write in cell A1 “Hurray”

b. if the resonse is No, then write a message box with the text “ZZZZZZ”

c. if the respnse is Cancel, then exit the sub

Expert Answer

 

‘ ***************It puts resonse and message into newly create EX_1_6 wrksheet************

‘ *************Vba code*****************

Option Explicit

Sub displayOptions()

‘declare variables
Dim result As String
Dim wkb As Workbook
Dim ws As Worksheet
Dim wb As Worksheet
Const strSheetName As String = “EX3_1_6”
Const strBookName As String = “wsEX6”

‘check for if worksheet EX3_1_6 already exsits
Set ws = Nothing
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets(strSheetName)
On Error GoTo 0
‘if it doesn’t exist then create one
If ws Is Nothing Then
Worksheets.Add.Name = strSheetName
End If

‘Add a new worksheet in the ned, assign code name =wsEX6
‘tab name = EX3_1_6

result = MsgBox(“Are you awake?”, vbYesNoCancel, “”)
‘put the response in cell A2
Worksheets(“EX3_1_6”).Range(“A2”).Value = result

Select Case result
Case vbYes
Worksheets(“EX3_1_6”).Range(“A1”).Value = “Hurray”
Case vbNo
MsgBox (“ZZZZZZ”)
Case vbCancel
Exit Sub

End Select

End Sub

` *************Output Screenshot****

` ***Code screenshot

Still stressed from student homework?
Get quality assistance from academic writers!