Go back to required cell to fill

erutherford

Active Member
Joined
Dec 19, 2016
Messages
449
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
 
And what was wrong with this script I provided in Post #17

Now it does not address the issue if someone clicks the cancel key.

We should get this working and then work on if cancel is clicked.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You said:
Partly - It won't print when empty, when I select "ok" or "cancel" on inputbox. If I enter data in the box and hit "ok" it won't print.

What does "Partly" mean??
So when does it work??
 
Upvote 0
Partly - It won't print when empty, when I select "ok" or "cancel" on inputbox. If I enter data in the box and hit "ok" it won't print. Would a "loop" function be appropriate?
I had a spelling error on the MyValue variable on one of the code lines. Here is the corrected code...
Code:
Private Sub CommandButton1_Click()
  If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    Cells(21, 3).Select
    Cancel = True
  End If
  MyValue = InputBox("Enter License Plate Info")
  If Len(Trim(MyValue)) Then
    Range("C21").Value = MyValue
    Range("A1:I50").PrintOut
  End If
 
Last edited:
Upvote 0
I had a spelling error on the MyValue variable on one of the code lines. Here is the corrected code...
Code:
Private Sub CommandButton1_Click()
  If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    Cells(21, 3).Select
    Cancel = True
  End If
  MyValue = InputBox("Enter License Plate Info")
  If Len(Trim(MyValue)) Then
    Range("C21").Value = MyValue
    Range("A1:I50").PrintOut
  End If

That did it!!!! Thank you very much!!!! Thanks for hanging in until the end!
 
Upvote 0
This script will give you a Input Box no matter if Cells(21,3) has a value or does not have a value. So why is the Message Box needed?
Good point! Maybe this arrangement is better...
Code:
Private Sub CommandButton1_Click()
  If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    Cells(21, 3).Select
    Cancel = True
    MyValue = InputBox("Enter License Plate Info")
    If Len(Trim(MyValue)) Then
      Range("C21").Value = MyValue
    Else
      Exit Sub
    End If
  End If
  Range("A1:I50").PrintOut
End Sub
 
Upvote 0
That works.

Not sure why this line of code is needed:

Code:
Cells(21, 3).Select





Good point! Maybe this arrangement is better...
Code:
Private Sub CommandButton1_Click()
  If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    Cells(21, 3).Select
    Cancel = True
    MyValue = InputBox("Enter License Plate Info")
    If Len(Trim(MyValue)) Then
      Range("C21").Value = MyValue
    Else
      Exit Sub
    End If
  End If
  Range("A1:I50").PrintOut
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,308
Members
448,886
Latest member
GBCTeacher

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