sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
When I run this piece- the msgbox response doesn't seem to matter- it to delete the sheet and then create a new one whether I hit 'yes, 'no' or cancel.

Note: the VoyageSpecificsCreate is a HUGE formatting piece- just for the application pieces there.

Code:
Sub VoyageSpecifics()' VoyageSpecifics Macro
' This controls a page that has all of the Voyage Specifics saved on it
'Speeds up the formating part
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    Application.ScreenUpdating = False
'Error Checks for a Voyage Specifics Sheet already existing
    If SheetExists("Voyage Specifics") Then
        MsgBox "Voyage Specifics Sheet already exists, would you like to delete it and start over?", vbYesNoCancel
        If vbYes Then
            Sheets("Voyage Specifics").Delete
            Call VoyageSpecificsCreate
        ElseIf vbNo Then
            Sheets("VoyageSpecifics").Select
            Exit Sub
        End If
    Else: Call VoyageSpecificsCreate
    End If
    'Speeds up the formating part
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The msgbox doesn't seem to be working here. If I hit 'no or 'cancel it still wants to delete the sheet and then create a new one. Did I write this piece incorrectly?

Also for the delete piece- it asks, per msgbox, if I want to delete the sheet. Then excel asks if I want to delete because it will be permanent- is there a way to remove that extra dialog box and just execute the delete?

Thanks for the help

Code:
Sub VoyageSpecifics()' VoyageSpecifics Macro
' This controls a page that has all of the Voyage Specifics saved on it
'Speeds up the formating part
'Error Checks for a Voyage Specifics Sheet already existing
    If SheetExists("Voyage Specifics") Then
        MsgBox "Voyage Specifics Sheet already exists, would you like to delete it and start over?", vbYesNoCancel
        If vbYes Then
            Sheets("Voyage Specifics").Delete
            Call VoyageSpecificsCreate
        ElseIf vbNo Then
            Sheets("VoyageSpecifics").Select
            Exit Sub
        End If
    Else: Call VoyageSpecificsCreate
    End If
    'Speeds up the formating part
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Dim the messagebox as a variable and it will work
Code:
MB = MsgBox("Voyage Specifics Sheet already exists, would you like to delete it and start over?", vbYesNoCancel)
If MB = vbYes Then
    'code
ElseIf MB = vbNo Then
    'code
End If

For the popup problem,
Code:
[COLOR=#333333]Application.DisplayAlerts = False[/COLOR]

Put this line before closing the workbook
 
Upvote 0
You have to assign the output from the MsgBox function to a variable and then test that variable against vbYes and vbNo...
Code:
[table="width: 500"]
[tr]
	[td]        Answer = MsgBox("Voyage Specifics Sheet already exists, would you like to delete it and start over?", vbYesNoCancel)
        If Answer = vbYes Then
            Sheets("Voyage Specifics").Delete
            Call VoyageSpecificsCreate
        ElseIf Answer = vbNo Then
            Sheets("VoyageSpecifics").Select
            Exit Sub
        End If[/td]
[/tr]
[/table]
 
Upvote 0
Try this , it captures the response as an integer
Code:
Sub xccfrf()
Dim Rsp As Integer
       Rsp = MsgBox("Voyage Specifics Sheet already exists, would you like to delete it and start over?", vbYesNoCancel)
        If Rsp = 6 Then
            MsgBox "YES  - " & Rsp
        ElseIf Rsp = 7 Then
            MsgBox "NO"
        Else
        MsgBox "Rsp " & Rsp
        End If
End Sub
 
Upvote 0
@sassriverrat
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. (rule 12 here: Forum Rules).
I have merged both threads.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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