I've added a "print" button with a simple recorded macro into a spreadsheet. When the user hits the print button, I need something that looks at cell P14 and shows an error message if the value = 1, also it needs to look at P15 and show a different error message if that value = 1. If either are one, the print macro should halt until both values return to 0. HELP! Thanks!!!
Last edited by pduback; 06-28-2011 at 04:25 PM.
Hello pduback,
Welcome to the Forum!
It would help to see the recorded macro code. What do you want each error message to say?
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks - glad I found this place! I actually deleted the macro for some random reason. Sounds like it would be helpful if I re-recorded it and posted? The message would be custom...something like "Fee schedules must be entered in descending order, please adjust..." I've written a formula into P14 to = 1 if the condition isn't met, 0 if it has been met. I'll re-record the macro and post it. Thanks for your help!
Here's the macro that I recorded to print. Any help would be HUGELY appreciated!
Sorry, forgot to paste it in:
Sub Print_Macro() ' ' Print_Macro Macro ' ' Sheets("Fee Calculator").Select Sheets("Printed Schedule").Visible = True Sheets("Fee Calculator").Select ActiveWindow.SelectedSheets.Visible = False Sheets("Printed Schedule").Select ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)" Sheets("Printed Schedule").Select Sheets("Fee Calculator").Visible = True Sheets("Printed Schedule").Select ActiveWindow.SelectedSheets.Visible = False End Sub
Last edited by Leith Ross; 06-28-2011 at 01:35 PM. Reason: Added Code Tags
Hello pduback,
Try this version of the macro. Change the message for P15. It is marked in bold.
Sub Print_Macro() ' ' Print_Macro Macro ' ' Sheets("Fee Calculator").Select Sheets("Printed Schedule").Visible = True Sheets("Fee Calculator").Select ActiveWindow.SelectedSheets.Visible = False Sheets("Printed Schedule").Select If Range("P14") = 1 Then MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly Exit Sub End If If Range("P15") = 1 Then MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly Exit Sub End If ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)" Sheets("Printed Schedule").Select Sheets("Fee Calculator").Visible = True Sheets("Printed Schedule").Select ActiveWindow.SelectedSheets.Visible = False End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
No luck with the additional code. If P14 or P15 (or both) are 1s, the print still goes off and no message box appears. Would love other ideas if you have them? Thanks again.
Hello pdubuck,
Could be we are not checking the correct sheet. The macro is using P14 and P15 on the "Printed Schedule". Is that the correct sheet?
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Nope. P14/15 are on "Fee Calculator"
Don't want to monkey with it until you tell me what to do...
Hello pduback,
Okay, this should work.
Sub Print_Macro() ' ' Print_Macro Macro ' ' Sheets("Fee Calculator").Select Sheets("Printed Schedule").Visible = True Sheets("Fee Calculator").Select If Range("P14") = 1 Then MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly Exit Sub End If If Range("P15") = 1 Then MsgBox "Fee schedules must be entered in descending order, please adjust..." , vbExclamation+vbOKOnly Exit Sub End If ActiveWindow.SelectedSheets.Visible = False Sheets("Printed Schedule").Select ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)" Sheets("Printed Schedule").Select Sheets("Fee Calculator").Visible = True Sheets("Printed Schedule").Select ActiveWindow.SelectedSheets.Visible = False End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Great - that solved that. One thing....if the error message is triggered, the macro stops, but the "Printed Schedule" page is left unhidden....can you add code to it to make it so if the error message is displayed, Printed Schedule remains hidden? Not sure if my questions are out of bounds for the forum - i'll trust you to tell me if so - but I really appreciate the help. Pete
Is that just a matter of switching the order in the code?
Hello pduback,
In this case, yes. The Range property applies to the ActiveSheet unless it has been qualified with a worksheet name like below.
Worksheets("Sheet1").Range("A1")
Since "Fee Calculator" is made active before the IF...THEN statements, the Range is assumed to be on the active sheet which is "Fee Calculator".
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
I switched a few lines and it is working perfectly. THANKS!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks