Code to print all sheets named with a 4-digit code

palaeontology

Active Member
Joined
May 12, 2017
Messages
444
Office Version
  1. 2016
Platform
  1. Windows
I have a workbook with a very large number of sheets, some named with a word or a person's name, but many are named with a 4-digit number (eg: 3476, 6589, 2376, etc etc etc).

Is there a code that would print just Page 1 of all sheets that are named with a 4-digit number ?

Regards,

John
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe try something like this, if your sheets can have 0001 etc just tweak the if statement to suit , i.e. checking it's numeric etc and less than 10000


Code:
Sub PrintNames()
 
    For I = 1 To Sheets.Count
      If Sheets(I).Name >= 1000 And Sheets(I).Name <= 9999 Then Sheets(I).PrintOut From:=1, To:=1
    Next I
End Sub
 
Upvote 0
Or
Code:
Sub t()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
    If Len(sh.Name) = 4 And IsNumeric(sh.Name) Then
        sh.PrintOut 1, 1
    End If
Next
End Sub
 
Last edited:
Upvote 0
Or:

Code:
Sub test1()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

If ws.Name Like "####" Then
ws.PrintOut from:=1, to:=1
End If

Next ws

End Sub
 
Upvote 0
Thankyou to all of you, each code worked brilliantly,

thankyou so much,

Regards,

John
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,952
Members
448,535
Latest member
alrossman

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