Go back to required cell to fill

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390
Have the basics down, now just trying to make it easier for the end user. Cell C21 is a required cell to be fill, not not a Message pops up. I would like the vba to take them right to that cell.
Here is the code I am using.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Cells(21, 3).Value = "" Then

MsgBox "License No. requires input before print"

Cancel = True

End If

End Sub

thanks in advance
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,722
Office Version
  1. 2010
Platform
  1. Windows
Have the basics down, now just trying to make it easier for the end user. Cell C21 is a required cell to be fill, not not a Message pops up. I would like the vba to take them right to that cell.
Here is the code I am using.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Cells(21, 3).Value = "" Then

MsgBox "License No. requires input before print"
Cells(21, 3).Select

Cancel = True

End If

End Sub

thanks in advance
Add the red highlighted code line shown above.
 

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390
Thanks for the reply. Since I am very new to vba, so not sure what to suggest

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Cells(21, 3).Value = "" Then

MsgBox "License No. requires input before print"
Cells(21, 3).Select
Cancel = True

End If

End Sub
 

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390

ADVERTISEMENT

No, but everything I have looked at suggest that it should.
 

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390

ADVERTISEMENT

MsgBox appears, select Ok, but I don't get taken back to cell 21,3
 

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390
Did a simple test in a new workbook and it worked fine. Back to my project and I have the code assigned to "Workbook BeforePrint". Should I assign code to a "button" (macro)?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,722
Office Version
  1. 2010
Platform
  1. Windows
Did a simple test in a new workbook and it worked fine. Back to my project and I have the code assigned to "Workbook BeforePrint". Should I assign code to a "button" (macro)?
It sounds to me like you may have other event code which is interfering with the BeforePrint event code.



Should I assign code to a "button" (macro)?
I don't see how that would do what you want (automatic reaction when a user tries to print).
 

erutherford

Active Member
Joined
Dec 19, 2016
Messages
390
It sounds to me like you may have other event code which is interfering with the BeforePrint event code.




I don't see how that would do what you want (automatic reaction when a user tries to print).

Not sure why it worked, but added the code to a form control button in a new module and it worked. I didn't see any conflicts but at my level it doesn't mean there isn't . I am not sure if putting this in a module is proper. Still have a long road to go down in vba.

Thanks for your effort and at least now I know a little more vba than before!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,514
Messages
5,602,086
Members
414,501
Latest member
mdhaumyu

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
Top