Message boxes

papadogiannakis

New Member
Joined
Nov 22, 2018
Messages
3
Hello, I have a problem that I just can't figure out. I wrote some code to print stickers. However it doesn't seem to do what I want it to do.

Code:
Sub VRBG()

Dim msgValue
msgValue = MsgBox("Heb commerciele media?", vbYesNo, "Stickers printen!")
If msgValue = vbYes Then
        Sheets("VRBG").Select
        ActiveSheet.Cells(2, 8).Select
        ActiveCell.Value = InputBox("Wat is de Batch Code?")
        
        ActiveSheet.Cells(4, 8).Select
        ActiveCell.Value = InputBox("Wat is de Houdbaarheidsdatum? DD-MM-JJJJ")
        
        ActiveSheet.Cells(8, 8).Select
        ActiveCell.Value = InputBox("Hoeveel stickers wil je?")
        msgValue = MsgBox("Zit je op Pathogenen?", vbYesNo, "Commerciele Stickers Printen")
            If msgValue = vbYes Then
                Sheets("VRBG").Select
                ActiveSheet.PageSetup.PrintArea = "$G$1:$I$5"
                ActiveSheet.PrintOut Copies:=Worksheets("VRBG").Range("H8"), ActivePrinter:="DYMO Labelwriter 450 Duo Label"
                Sheets("Buttons").Select
            
            If msgValue = vbNo Then
                msgValue = MsgBox("Zit je in de Mediakeuken/Kantoor?", vbYesNo, "Stickers Printen")
                If msgValue = vbYes Then
                    Sheets("VRBG").Select
                    ActiveSheet.PageSetup.PrintArea = "$G$1:$I$5"
                    ActiveSheet.PrintOut Copies:=Worksheets("VRBG").Range("H8"), ActivePrinter:="DYMO Labelwriter Duo Label"
                    Sheets("Buttons").Select
If msgValue = vbNo Then
    msgValue = MsgBox("Zit je in de Mediakeuken/Kantoor?", vbYesNo, "Zelfgemaakte Stickers Printen")
        If msgValue = vbYes Then
            Sheets("VRBG").Select
            ActiveSheet.PageSetup.PrintArea = "$A$1:$C$5"
            ActiveSheet.PrintOut Copies:=Worksheets("Buttons").Range("B4"), ActivePrinter:="DYMO Labelwriter Duo Label"
            Sheets("Buttons").Select
    
        ElseIf msgValue = vbNo Then
            msgValue = MsgBox("Zit je op Pathogenen?", vbYesNo, "Stickers Printen")
            If msgValue = vbYes Then
                Sheets("RVS").Select
                ActiveSheet.PageSetup.PrintArea = "$A$1:$C$5"
                ActiveSheet.PrintOut Copies:=Worksheets("Buttons").Range("B4"), ActivePrinter:="DYMO Labelwriter 450 Duo Label"
                Sheets("Buttons").Select
                
End If
End If
End If
End If
End If
End If
End If
End Sub

When I run the macro the first message box pops up, however if I click on 'no' it stops when It should ask me another question. Why doesn't it continue?

Thanks in advance! :)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The nesting of your If/End If's is incorrect, and since the message box can only return one of two values, you don't need to test for both of them. The structure should be something like this:

Code:
If msgValue = vbYes Then
'your code goes here
Else
msgValue  MsgBox ("blah blah",vbYesNo)
If msgValue = vbYes Then
'your code goes here
Else
'your code goes here
End If
End If


Also, it's best not to select cells, so this
Code:
ActiveSheet.Cells(2, 8).Select
ActiveCell.Value = InputBox("Wat is de Batch Code?")

becomes this
Code:
ActiveSheet.Cells(2, 8) = InputBox ("Wat is de Batch Code?")
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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