Re: Add a Confirmation Message Box to a macro?

raymangoose

New Member
Joined
Feb 22, 2015
Messages
7
Re: Add a Confirmation Message Box to a macro?

I have this code that prints everything from data validation, but I also want to run a massage that says "are you sure you want to continue" before running the code. My code works separately but not with the massage code.

Code:
Sub ClearINV()


Answer = MsgBox("Are you sure you want to continue?", vbYesNoCancel + vbInformation, "Application Message")






If Answer = vbYes Then Else Exit Sub


If Answer = vbYes Then Else Exit Sub
 Sub Iterate_Through_data_Validation()
    Dim xRg As Range
    Dim xCell As Range
    Dim xRgVList As Range
    Set xRg = Worksheets("Lease Abstract").Range("I2")
    Set xRgVList = Evaluate(xRg.Validation.Formula1)
    For Each xCell In xRgVList
        xRg = xCell.Value
        ActiveSheet.PrintOut
    Next
End Sub
End If
End Sub
 
Last edited by a moderator:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Re: Add a Confirmation Message Box to a macro?

Hi & welcome to MrExcel
How about
Code:
Sub ClearINV()


If MsgBox("Are you sure you want to continue?", vbYesNoCancel + vbInformation, "Application Message") = vbYes Then
    Dim xRg As Range
    Dim xCell As Range
    Dim xRgVList As Range
    Set xRg = Worksheets("Lease Abstract").Range("I2")
    Set xRgVList = Evaluate(xRg.Validation.Formula1)
    For Each xCell In xRgVList
        xRg = xCell.Value
        ActiveSheet.PrintOut
    Next
End If
End Sub
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

Thanks a lot for the answer I am very new to VBA

When I debug it works, but when I run the actual macro it syas "Can not run macro "the file name and macro name". The macro may not be available in this workbook or all macros may be disabled.


Hi & welcome to MrExcel
How about
Code:
Sub ClearINV()


If MsgBox("Are you sure you want to continue?", vbYesNoCancel + vbInformation, "Application Message") = vbYes Then
    Dim xRg As Range
    Dim xCell As Range
    Dim xRgVList As Range
    Set xRg = Worksheets("Lease Abstract").Range("I2")
    Set xRgVList = Evaluate(xRg.Validation.Formula1)
    For Each xCell In xRgVList
        xRg = xCell.Value
        ActiveSheet.PrintOut
    Next
End If
End Sub
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

How are you trying to run it?
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

one last question. Is there way to this all by calling the print dialogue screen?
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

Fraid I don't understand what you're asking.
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

Can you please help me to add something in this code that I will be able to cancel while printing? When it starts printing even if I press cancel it doesn't stop. Also it prints the blank sheets too.

Thanks a lot

nevermind this is good enough. thanks again
 
Upvote 0
Re: Add a Confirmation Message Box to a macro?

Can you please help me to add something in this code that I will be able to cancel while printing?
I don't know if that's possible, let alone how to do it, assuming that it is possible.
 
Upvote 0

Forum statistics

Threads
1,212,934
Messages
6,110,762
Members
448,295
Latest member
Uzair Tahir Khan

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