Is there any way in Excel to make it so that a particular tab isn't included when you print the entire workbook? As in, Sheet1, Sheet2, and Sheet3 print, but not Sheet4.
So like when someone goes to File -> Print or whatever, and hit OK, etc, everything prints out except for a particular designated tab (which I assume I have to "hide from printing" somehow).
I'm sending this workout out to a bunch of people so I'm trying to avoid forcing them to enable/run macros and all that stuff. Is there just a property of a sheet somewhere like "exclude from print"?
These answers will require the use of macros.
Hide the sheet before printing.
sheets("WorksheetToNotPrint").visible = xlSheetHidden 'or 0
or
sheets("WorksheetToNotPrint").visible = xlSheetVeryHidden 'or 2
'used if you don't want people to unhide the worksheet without knowing code
and
sheets("WorksheetToNotPrint").visible = xlSheetVisible 'or -1
when done
another option is to print the sheets you want printed (may be useful if you only want a few sheets printed:
Sub Print_Specific_Sheets()
Sheets(Array("Sheet1", "Sheet2", "Sheet4")).Select
ActiveWindow.SelectedSheets.PrintOut
Sheets("Sheet1").Select
End Sub
Actually the answer seems to be surprisingly simple.
If you hide the sheet, it will not be printed when you print the entire workbook.
You won't need a macro, just
right click on the sheet name
choose hide
If needed you or other users can unhide it as well.
If you use the BeforePrint event then you can alter what the built in print function can do. The BeforePrint macro is inside 'ThisWorkbook' under 'Workbook'.
For example you can hide sheet 4 so it doesn't print like this:
Private Sub aWorkbook_BeforePrint(Cancel As Boolean)
Sheets(4).Visible = xlSheetHidden
End Sub
The downside to this method is there is no AfterPrint method to unhide the sheets. So you need to circumvent the print dialog. There are several ways to do this but here is one very simplistic method. (Note: This might not be a good solution if you have many other printing scenarios that you need to account for)
Here I am telling exactly what sheets to print (only sheet 1 and 4). You can use names instead of numbers and you can even create a loop and look for variables to determine what sheets you want to print.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
Sheets(Array("1", "4")).PrintOut , , 1
Application.EnableEvents = True
'//prevent the default print
Cancel = True
End Sub
Just set the print area on the tab you don't want to print to a single blank Cell, This will mean that it will print a single blank page rather than the reams of data that I presume you are trying to avoid printing.
To do this manually just select all the sheets you want to print by clicking on the first sheet tab label, then hold down the 'Shift' key and click on the last sheet tab label. (If you have a large number of sheets use the small arrow keys to navigate)
If you need to unselect a sheet in the middle hold down the CTRL key and click that sheet.
Alternately you can hold the CTRL key and click on each sheet tab label.
The sheet colour will be white (with a gradient on the none active sheet) to show they have been selected.
WARNING: When multiple sheets are selected any change on one will be repeated in the same cells on all of them.
If you do not want to use VBA or hide the sheet, you could just set print area on an empty cell of the sheet you do not want to print.
The tab will still be printed but the result will be an empty sheet.
Using an easy Macro:
Just put this lines inside a new Macro, and replace the names of the sheets yo DO want to be printed:
Sheets(Array("Name_of_Sheet_1", "Name_of_Sheet_2")).Select
Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")
Why all the crazy coding?
Just click on the first tab you want to print and make it active.
Then hold down control, and click on each additional tab you want to print, excluding the tab, or tabs you don't want to print.
Then go to "file" and then "print" like you normally would. Make sure "print active sheets" is selected, then print.
It prints only the tabs you selected.
Simple, and no need to complicate things to ridiculous levels of unnecessary silliness.
Related
Hi I am kind of new to VBA and i can't seem to find what i am looking for.
What i want to make is a macro that links to another page in my workbook that refers to data in a certain cell.
from certain datapoints i have a cell set up that as everything is filled in it gives the name of the page i want to link to (lets say "overview_Oct_2020" by filling in the month and year in other cells), and when running the macro go to that.
I seem to totally blank on how to do it. I made a =HYPERLINK() version pretty easily, but i want to change that to a button, hence the reason for a macro.
so technically i want to make a button with a macro that goes to [TEXT IN CEL A1]!A1
Put this macro in a standard module and assign it to a button on the worksheet
Sub link()
Dim textInCelA1 as String
textInCelA1 = Range("A1").value
Sheets(textInCelA1).Activate
Range("A1").Select
End Sub
I try to use the following command on several buttons in different worksheets of myexcel workbook.
MsgBox (ActiveSheet.Shapes(Application.Caller).TopLeftCell.row)
When copying those buttons to another area of my workbook, I sometimes have the problem that still the row number of the original button location is displayed. As example in the screenshot below, I click the button at the bottom, but it return row 705 instead of 739. Can anyone explain this behaviour?
Make sure all your buttons have unique names. Somtimes it can happen that copied buttons have the same name (due to a bug in Excel). Then VBA cannot distinguish them and uses the first one that it finds. Check all your button names and make sure they are unique.
This issue can be reproduced easily:
Open a new workbook
Add a button (FormControl)
Name it MyButton
Copy that button
Paste it somewhere else in the same sheet
Use the code from the question for both buttons
The button will now always show the row of the first button, because both have the exact same name.
Image 1: Illustration how this issue can occur. In the end both buttons show the same row value. Because they have the same name VBA only can find the first one.
The soulution is, when ever you copy a button immediately make sure you rename it to a unique name.
It never happened to me to copy a shape with the same name. Only its Caption remained... But, since people says it is possible, try assigning this code to all the shapes in discussion, please. If the shape double name would be the reason, the code will return twice:
Sub callButName()
Dim sh As Shape
For Each sh In ActiveSheet.Shapes
If sh.Name = Application.Caller Then MsgBox sh.TopLeftCell.Address
Next
End Sub
I have the following code to simulate some cells behave like buttons
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Application.ScreenUpdating = False
If Target.Cells.Count = 1 Then
'~~~~~~ pseudocode ~~~~~~
If {select cell is one of the chose ones}
{do some stuff}
End If
'~~~~~~ pseudocode ~~~~~~
End If
Range("A1").Select
'Application.ScreenUpdating = True
End Sub
It doesn't matter whereas I use the ScreenUpdating code, the "Selection box" is flying around from A1 to the selected cell and back and it make the sheet much slower.
Can this flying (animation) selection box be stoped?
So far I have found this, not possible to hide, but noting about the flying efect:
Hide the cell selection box in Excel
Edit:
I need (I think so) edit capabilities on the sheet, therefore the option of not changing selection cell is not applicable. Due to:
most of the sheet is informative, and should be available for copy (not edited)
some cells are input forms (free text thing), selection as usual
some cells should behave like buttons (plus/minus for a numeric value, sclaes, simple stuff, but thousand of then, so much easier do/maintain by code), and user must not edit them
grouping should be available, (so that's complicate protecting the sheet)
I am not closed to the option : Range("A1").Select after each (most) of user interaction, but no other method comes into mind to me now.
An example:
I know some would say: "you should make this out from excel", and I agree with you, but this is a mandatory thing, I do not have the power to raise this question
As you can see, I got the "flying selection" that I try to get rid off
cell A1 is already hodden, that will do most of the trick
final version sure will go with hidden gridlines and headlines
rows groups exist, and are important, so no protection possible
all the functionality, I can do easy with vba, just problem with the animation
Maybe this is not the answer that you have been waiting for, but as Mathieu mentioned in his comment, please try to avoid using Selection.
It does make things slower and often causes errors (in example try selecting cell from hidden sheet). Instead just do something with the range that you define with your if statements directly. Every property of Cell or Range can be accessed directly.
Hope it helps.
Not sure how you can achieve you "flying select box" problem, but at least you could add this code, so opening/closing groups are available on protected sheets:
'Password Protect Current Sheet
ActiveSheet.Protect Password:="Add_here_your_password", UserInterfaceOnly:=True
'Enable Group Collapse/Expand Capabilities
ActiveSheet.EnableOutlining = True
How about trying to remove the "back to A1" as much as possible?
Maybe do it only on absolutely necessary, or move back to the changed value (the 33 in your example), or to the question title (in your multi-option example)
Is there any way in Excel to make it so that a particular tab isn't included when you print the entire workbook? As in, Sheet1, Sheet2, and Sheet3 print, but not Sheet4.
So like when someone goes to File -> Print or whatever, and hit OK, etc, everything prints out except for a particular designated tab (which I assume I have to "hide from printing" somehow).
I'm sending this workout out to a bunch of people so I'm trying to avoid forcing them to enable/run macros and all that stuff. Is there just a property of a sheet somewhere like "exclude from print"?
These answers will require the use of macros.
Hide the sheet before printing.
sheets("WorksheetToNotPrint").visible = xlSheetHidden 'or 0
or
sheets("WorksheetToNotPrint").visible = xlSheetVeryHidden 'or 2
'used if you don't want people to unhide the worksheet without knowing code
and
sheets("WorksheetToNotPrint").visible = xlSheetVisible 'or -1
when done
another option is to print the sheets you want printed (may be useful if you only want a few sheets printed:
Sub Print_Specific_Sheets()
Sheets(Array("Sheet1", "Sheet2", "Sheet4")).Select
ActiveWindow.SelectedSheets.PrintOut
Sheets("Sheet1").Select
End Sub
Actually the answer seems to be surprisingly simple.
If you hide the sheet, it will not be printed when you print the entire workbook.
You won't need a macro, just
right click on the sheet name
choose hide
If needed you or other users can unhide it as well.
If you use the BeforePrint event then you can alter what the built in print function can do. The BeforePrint macro is inside 'ThisWorkbook' under 'Workbook'.
For example you can hide sheet 4 so it doesn't print like this:
Private Sub aWorkbook_BeforePrint(Cancel As Boolean)
Sheets(4).Visible = xlSheetHidden
End Sub
The downside to this method is there is no AfterPrint method to unhide the sheets. So you need to circumvent the print dialog. There are several ways to do this but here is one very simplistic method. (Note: This might not be a good solution if you have many other printing scenarios that you need to account for)
Here I am telling exactly what sheets to print (only sheet 1 and 4). You can use names instead of numbers and you can even create a loop and look for variables to determine what sheets you want to print.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
Sheets(Array("1", "4")).PrintOut , , 1
Application.EnableEvents = True
'//prevent the default print
Cancel = True
End Sub
Just set the print area on the tab you don't want to print to a single blank Cell, This will mean that it will print a single blank page rather than the reams of data that I presume you are trying to avoid printing.
To do this manually just select all the sheets you want to print by clicking on the first sheet tab label, then hold down the 'Shift' key and click on the last sheet tab label. (If you have a large number of sheets use the small arrow keys to navigate)
If you need to unselect a sheet in the middle hold down the CTRL key and click that sheet.
Alternately you can hold the CTRL key and click on each sheet tab label.
The sheet colour will be white (with a gradient on the none active sheet) to show they have been selected.
WARNING: When multiple sheets are selected any change on one will be repeated in the same cells on all of them.
If you do not want to use VBA or hide the sheet, you could just set print area on an empty cell of the sheet you do not want to print.
The tab will still be printed but the result will be an empty sheet.
Using an easy Macro:
Just put this lines inside a new Macro, and replace the names of the sheets yo DO want to be printed:
Sheets(Array("Name_of_Sheet_1", "Name_of_Sheet_2")).Select
Application.CommandBars.ExecuteMso ("PrintPreviewAndPrint")
Why all the crazy coding?
Just click on the first tab you want to print and make it active.
Then hold down control, and click on each additional tab you want to print, excluding the tab, or tabs you don't want to print.
Then go to "file" and then "print" like you normally would. Make sure "print active sheets" is selected, then print.
It prints only the tabs you selected.
Simple, and no need to complicate things to ridiculous levels of unnecessary silliness.
I am trying to create in excel where you enter initials into a cell and the person's full name appears automatically so they do not have to enter their full name every time in a spreadsheet. I have managed to replicate this using nested if statements for different people which works fine but currently it requires two cells and I want to have it on the same cell. I have noticed that if I change the the formula to be in the same cell then it comes up with "circular reference warning" and does not work and if I try to enter text in that cell it replaces the formula. Just wondering is this possible?
=IF(C29="HB", "hazel", IF(C29="AO", "amelia", ""))
You could use Excel's AutoCorrect feature to do this.
Go to File..Options..Proofing -
Click on AutoCorrect Options..
Enter a pair (or triplet) of initials you want to replace and the name you want the initials to be replaced with, then click add. You can then continue adding Replace With definitions.
It doesn't matter if you enter the Replace in lower case "hb" or upper case "HB" because the entry and its replacement are both added to the definitions in lower case.
Excel does this for a reason - it is sensitive to the case of the cell entry. That is to say if you enter "hb" the autocorrect will change this to "hazel"; if you enter "Hb" you will get "Hazel"; and "HB" will give you "HAZEL".
The replacement pairs you enter will only apply to the currently logged username. The replacement pairs will be there every time you open Excel and are available to all open workbooks.
If you want the replacement pairs to be available to other users you will need to:
manually add the replacement pairs to all desired users Excel Options or
develop a macro to add them using Application.AutoCorrect.AddReplacement "hb", "hazel"
If you decide to go down the macro path, you may want to limit the scope of definitions by entering them in certain workbook or worksheet events and consider using the Application.AutoCorrect.DeleteReplacement "hb" method.
Workbook_Open
The replacements will be available to the current user in all workbooks and will remain until the are deleted manually or programmatically.
Workbook_Activate and Workbook_Deactivate
If you use the AddReplacement method in Workbook_Activate and the DeleteReplacement method in Workbook_Deactivate then the replacements will only be available to sheets in the workbook containing the code.
Worksheet_Activate and Worksheet_Deactivate
Place the code in a sheet module within the above sheet event handlers and the replacements will only be available in the sheet corresponding to that module.
This is just an example that you can adapt to your needs. The initials input will be in column A so if the user types JW in a cell in that column, the cell will change to James Ravenswood.
Put the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
ary = Array("JW", "VL", "BJM")
bry = Array("James Ravenswood", "Victor Laszlo", "Bullwinkle J Moose")
Set A = Range("A:A")
If Intersect(Target, A) Is Nothing Then Exit Sub
v = Target.Value
For i = LBound(ary) To UBound(ary)
If v = ary(i) Then
Application.EnableEvents = False
Target.Value = bry(i)
Application.EnableEvents = True
Exit Sub
End If
Next i
End Sub
You would need to fill ary and bry with your initials and names.
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!