BA Code - Set print area on selected WS from a range of names

thetcispaniard

New Member
Joined
May 31, 2017
Messages
3
Hi,

Almost there but not quite! Bit of a newbie on the VBA besides what I have gleaned off this site and others.

Goal - set a consistent print range across multiple worksheets.

The issue I have is that it doesn't seem to work lol.

So far - I have defined the worksheet names on the 'Input' WS in range B22-B35 and tried to set the print area using the following code:

Sub Set_Lead_Sheet_Print_Area()
Dim sPrintArea As String
Dim rng As Range
Dim WS As Worksheet Application.ScreenUpdating = False
For Each rng In Sheets("Inputs").Range("B22:B35")
If Trim(rng.Value) <> "" Then
On Error Resume Next
Set WS = Nothing
Set WS = Sheets(rng.Value)
On Error GoTo 0
If WS Is Nothing Then
MsgBox "Sheet " & rng.Value & " does not exist"
Else
sPrintArea = "B1:W72"
End If
End If
Next rng
End Sub

Thanks in advance.
CM
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
See if this works:

Hi,

Almost there but not quite! Bit of a newbie on the VBA besides what I have gleaned off this site and others.

Goal - set a consistent print range across multiple worksheets.

The issue I have is that it doesn't seem to work lol.

So far - I have defined the worksheet names on the 'Input' WS in range B22-B35 and tried to set the print area using the following code:

Sub Set_Lead_Sheet_Print_Area()
Dim sPrintArea As String
Dim rng As Range
Dim WS As Worksheet Application.ScreenUpdating = False
For Each rng In Sheets("Inputs").Range("B22:B35")
If Trim(rng.Value) <> "" Then
On Error Resume Next
Set WS = Nothing
Set WS = Sheets(rng.Value)
On Error GoTo 0
If WS Is Nothing Then
MsgBox "Sheet " & rng.Value & " does not exist"
Else
sPrintArea = "B1:W72"
WS.PageSetup.PrintArea = sPrintArea
End If
End If
Next rng
End Sub

Thanks in advance.
CM
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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