Print specific tabs when tab name is a cell value

OhioExcelGuy

New Member
Joined
Dec 7, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am a new member but have found numerous posts here that have helped tremendously in the past. I do have one I cannot seem to figure out or find a previous thread that will cover.

I have a workbook with numerous tabs. Some of which are are named as years (2020, 2021, 2022, etc...). What I am wanting to do is enter a specific year in a cell in an "Input" tab and have a module (that can be added to a button) that recognizes that cell value and prints the corresponding tab with that year as the name. The "Input" sheet is Sheet26, if that is needed for the code.

So in summary, I would like to be able to enter "2022" into cell D3 of the "Input" tab, then be able to press a button and the tab named "2022" will be printed to pdf.

I apologize if there is already a thread that covers this. If there is, can someone point me to it?

Thanks in advance!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I am a new member but have found numerous posts here that have helped tremendously in the past. I do have one I cannot seem to figure out or find a previous thread that will cover.

I have a workbook with numerous tabs. Some of which are are named as years (2020, 2021, 2022, etc...). What I am wanting to do is enter a specific year in a cell in an "Input" tab and have a module (that can be added to a button) that recognizes that cell value and prints the corresponding tab with that year as the name. The "Input" sheet is Sheet26, if that is needed for the code.

So in summary, I would like to be able to enter "2022" into cell D3 of the "Input" tab, then be able to press a button and the tab named "2022" will be printed to pdf.

I apologize if there is already a thread that covers this. If there is, can someone point me to it?

Thanks in advance!
I should also add that I would like it to print to the same file location as the workbook is saved. I have already figured out code to print multiple tabs to a pdf using the code below, but cannot figure out how to include a cell reference as a sheet name instead of entering the sheet name itself.

Sub Print_Calculations()

Dim PDFfile As String

PDFfile = ActiveWorkbook.Path & "\" & Worksheets("Index").Range("A8") & " " & Worksheets("Index").Range("B8") & ".pdf"
Sheets(Array("2016", "2017")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

MsgBox "PDF Files have been created"

End Sub
 
Upvote 0
I fumbled upon the solution in another thread here:

 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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