G
George
Hi.
I am looking for a macro to not let blank and select the cell before
printing..
Thank you.
I am looking for a macro to not let blank and select the cell before
printing..
Thank you.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
When you change the code, it's a good idea to post what you tried. It may give
a hint to what you need.
Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim myCell As Range
Dim myRng As Range
Set myRng = Me.Worksheets("sheet1").Range("a1,b3,c12:c18")
If Application.CountA(myRng) = myRng.Cells.Count Then
'all filled in, do nothing
Else
For Each myCell In myRng.Cells
With myCell
If IsEmpty(.Value) Then
Application.Goto .Cells, scroll:=True
MsgBox "Can't print without all cells in: " _
& myRng.Address(0, 0) & " filled"
Cancel = True
Exit For
End If
End With
Next myCell
End If
End Sub
You could use it in the beforesave event. But remember, it might make it more
difficult for you to save the file when you're developing it. You'd want to
give yourself a way to save without filling in those cells--maybe checking
application.username to see if it was you.
If your data has a column that could be used to determine that last used row,
then you could check all the cells between row 2 (say) and that last used row in
certain columns.
Personally, as a user, I would find this irritating. If I wanted to save and go
to lunch and come back, your code would stop me. Even if I made significant
changes that I was afraid to lose, your code may stop me.
////And these lines:
Selected the first cell that was empty and gave a message box.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.