VBA Select Case for a vbyesno msgbox

Lewzerrrr

Active Member
Joined
Jan 18, 2017
Messages
256
Hi,

Trying to use the following code that if my inputbox is empty then display a msgbox vbyesno asking if i'm sure I want to continue.. however I can't get control over the 2nd argument, excel just passes through the second argument no matter what is in there. (see line in bold, if I click no it won't do anything), I've tried adding another if vbno then but that doesn't prevail :D

What I need is if vbyes then do nothing, if vbno then use another inputbox..

How can I do this with select case AND if?

Code:
Sub InputBoxes()

Dim title As String, week As String
Dim rng1 As Range, rng2 As Range


Set rng1 = Sheets(1).Range("A1")


title = InputBox("Please enter the title of the sheet.")
rng1.Value = title


    If title = "" Then
        MsgBox "You haven't entered a title, are you sure you want to continue?", vbYesNo + vbExclamation
            If vbYes Then
                'do nothing
            Else
[B]                rng1.Value = InputBox("Please enter the title of the sheet.")[/B]
            End If
    End If
    
End Sub
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You will need to set a variable to store the vbYesNo outcome

Code:
Sub InputBoxes()


Dim title As String, week As String
Dim rng1 As Range, rng2 As Range
Dim ans As Variant


Set rng1 = Sheets(1).Range("A1")




title = InputBox("Please enter the title of the sheet.")
rng1.Value = title




    If title = "" Then
        ans = MsgBox("You haven't entered a title, are you sure you want to continue?", vbYesNo + vbExclamation)
            If ans = vbYes Then
                'do nothing
            Else
                rng1.Value = InputBox("Please enter the title of the sheet.")
            End If
    End If
    
End Sub
 
Upvote 0
try

Code:
Sub InputBoxes()


Dim title As String, week As String
Dim rng1 As Range, rng2 As Range




Set rng1 = Sheets(1).Range("A1")




title = InputBox("Please enter the title of the sheet.")
rng1.Value = title




    If title = "" Then
        MsgBox "You haven't entered a title, are you sure you want to continue?", vbYesNo + vbExclamation
            If vbNo Then
                rng1.Value = InputBox("Please enter the title of the sheet.")
            Else
                
            
            End If
    End If
    
End Sub


Hi,

Trying to use the following code that if my inputbox is empty then display a msgbox vbyesno asking if i'm sure I want to continue.. however I can't get control over the 2nd argument, excel just passes through the second argument no matter what is in there. (see line in bold, if I click no it won't do anything), I've tried adding another if vbno then but that doesn't prevail :D

What I need is if vbyes then do nothing, if vbno then use another inputbox..

How can I do this with select case AND if?

Code:
Sub InputBoxes()

Dim title As String, week As String
Dim rng1 As Range, rng2 As Range


Set rng1 = Sheets(1).Range("A1")


title = InputBox("Please enter the title of the sheet.")
rng1.Value = title


    If title = "" Then
        MsgBox "You haven't entered a title, are you sure you want to continue?", vbYesNo + vbExclamation
            If vbYes Then
                'do nothing
            Else
[B]                rng1.Value = InputBox("Please enter the title of the sheet.")[/B]
            End If
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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