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
 
I want to make sure that if someone else looks at this thread they can see a solid solution. So I went back in and deleted the modules created. I have a single worksheet now. I want the end user to be required to enter info in C21 BEFORE they print out the sheet. If they try to print out the sheet without the required info, then they are prompted to do so with a MsgBox. That is when I would like "vba" to take me back to C21. Once the data is entered then I am allow to print (specific range).

So where is the best place to assign the function? Within the sheet or in a Module? Does it matter if I use a cmd button or a form control button?

Here is the code I have been manipulating

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



I haven't figure out where the cell range should go.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If it is a WorkBook module as you have posted then it goes in the ThisWorkbook module.
 
Upvote 0
Getting closer! What is needed in this code to allow me to enter in the data in C21? With C21 empty, hit the print button (CmdButton1)the MsgBox popsup, but once I select ok, it prints the range without allowing me to fill in the data.


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
Range("A1:I50").PrintOut
End Sub
 
Upvote 0
If you want it to stop to input data then put in an inputbox line after the if test rather than/additional to the msgbox.
 
Upvote 0
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
PLACE IT HERE?
Range("A1:I50").PrintOut
End Sub
 
Upvote 0
It now works properly

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("gimme") - 'use any expression here
Range("C21").Value = myValue
Range("A1:I50").PrintOut
End Sub

Thanks to everyone that replied!!!!!!
 
Upvote 0
Your script should look like this:


Code:
Private Sub CommandButton1_Click()
Dim ans As Long
 If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    ans = InputBox("Enter Your License number")
    Cells(21, 3).Value = ans
 End If
 Range("A1:I50").PrintOut
 End Sub

OK
 
Upvote 0
looks like one more issue. If we cancel the input box, the page will still print!
What is required then?

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")
Range("C21").Value = myValue
Range("A1:I50").PrintOut
End Sub
 
Upvote 0
looks like one more issue. If we cancel the input box, the page will still print!
What is required then?

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")
Range("C21").Value = myValue
Range("A1:I50").PrintOut
End Sub
Maybe this...
Code:
Private Sub CommandButton1_Click()
  If Cells(21, 3).Value = "" Then
    MsgBox "License No. requires input before print"
    Cells(21, 3).Select
    [B][COLOR="#FF0000"]Cancel = True[/COLOR][/B]
  End If
  myValue = InputBox("Enter License Plate Info")
  If Len(Trim(myvaluue)) Then
    Range("C21").Value = myValue
    Range("A1:I50").PrintOut
  End If
End Sub
I left the highlighted code line in, but since this code is no longer in a event procedure, it does nothing useful any more.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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