Link to home
Start Free TrialLog in
Avatar of adamchicago
adamchicago

asked on

Apply formatting of one Excel worksheet to all BUT TWO worksheets

Experts, please help me with the code in the attached snippet that needs to apply the formatting of the worksheet "Pformat" and apply it to all other worksheets (names will not remain consistent) EXCEPT "Pformat" and "Format Sheets For Printing".

Thank you for any help!!!!
Sub Applyformats()
Dim sh As Worksheet
Worksheets("Pformat").Range("a1:ac1000").Copy
For Each sh In ActiveWorkbook.Sheets
    If sh = "Format Sheets For Printing" Or sh = "Pformat" Then
    GoTo skipp
    Else
    sh.Range("a1:ac1000").PasteSpecial xlPasteFormats
    Application.CutCopyMode = False 'Clear Clipboard
    End If
    
skipp:
    
Next sh
End Sub

Open in new window

Avatar of jppinto
jppinto
Flag of Portugal image

Just change this:

If sh = "Format Sheets For Printing" Or sh = "Pformat" Then


To this:

If sh.Name = "Format Sheets For Printing" Or sh.Name = "Pformat" Then
Avatar of adamchicago
adamchicago

ASKER

Thank you very much for the quick response...that fixed that part of the code but now I'm getting a Run-time error '1004'  "PasteSpecial method of Range class failed" ??  ...any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Remove this line:

Application.CutCopyMode = False 'Clear Clipboard

jppinto
Thanks
With all due respect, can you please explain me why you only accepted the solution provided by Rory?
I agree it should be a points split. I'd also love to hear the reason for the B grade.
That part I didn't noticed! I also don't understand why the B grade!?!