Get target sheet address from cell value

Coopercell

New Member
Joined
Apr 3, 2016
Messages
7
Hi
I am trying to make a generic print code that depending on what sheet it is activated from it will print the matching sheet for that page. I currently have the following code but am unsure of how to get it to reference the cell and retrive the codename of the sheet in which it has to print. I was looking to put the codename of the sheet I need printed in cell X1 of the starting sheet.

Sub PrintSpecificSheet1()
Dim wks As Worksheet

Set wks = ActiveWorkbook.Sheets(Sheet11.Name)
If wks.Visible <> xlSheetVisible Then
Application.ScreenUpdating = False
wks.Visible = xlSheetVisible
wks.Calculate
wks.Activate
wks.PrintOut Copies:=Sheets(Sheet4.Name).Range("X5").Value, IgnorePrintAreas:=False
wks.Visible = xlSheetHidden
Application.Goto Reference:=Worksheets(Sheet4.Name).Range("A1"), _
scroll:=True
Application.ScreenUpdating = True
Else
wks.PrintOut Copies:=Sheets(Sheet4).Range("X5").Value, IgnorePrintAreas:=False
Application.Goto Reference:=Worksheets(Sheet4).Range("A1"), _
scroll:=True
End If
Set wks = Nothing
End Sub

Thanks in advance
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The sheet codename is in a sheet cell? Don't understand why you want to reference any cell. What's missing from your info is how you're calling this sub, which possibly should be Sub PrintSpecificSheet1(strName As String) and not Sub PrintSpecificSheet1(). That way you could pass the sheet name or codename to the sub. If required, you could add parameters to the sub to include whatever else you might need.
Please post more than a few lines of code within code tags (use vba button on posting toolbar) and maintain indentation for easier reading.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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