Macro Error

ghrek

Active Member
Joined
Jul 29, 2005
Messages
276
Hi I have the following macro that comes with compile error expected end with.

Looking online it says I should have END SUB but already got that. Any ideas?

VBA Code:
Sub printshiftsheet()
'
' printshiftsheet Macro
'

    Const cPassword As String = "ccc"
   
    Dim oWs As Worksheet
    Set oWs = ThisWorkbook.Worksheets("ShiftSheet")

    With oWs
        .Unprotect Password:=cPassword
         Range("B10:D23").Select
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
 
    ActiveWorkbook.Save
        .PageSetup.PrintArea = "$A$3:$H$53"
        Range("B10:D23").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .PatternTintAndShade = 0
         .Range("D8").Value = .Range("D8").Value + 1
        Application.Dialogs(xlDialogPrint).Show
        .Cells.Locked = True
        .Cells.FormulaHidden = False
        .Range("C5:D7,H11:H22,H36:H40,D34:D38,B46:H47,G56:H56,C60:C71,G77:H77,C81:C88,G93:H93,C94:C101").Locked = False
        .Protect Password:=cPassword, DrawingObjects:=False, Contents:=True, Scenarios:=False
        oWs.Parent.Save

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,139
Office Version
  1. 365
Platform
  1. Windows
You will need an End With after each of your With sections.
 

ghrek

Active Member
Joined
Jul 29, 2005
Messages
276

ADVERTISEMENT

Ive tried doing the end with in all manners and keep coming up with an error.

What have I done wrong. Macro below



VBA Code:
    Const cPassword As String = "shreked"
    
    Dim oWs As Worksheet
    Set oWs = ThisWorkbook.Worksheets("ShiftSheet")

    With oWs
        .Unprotect Password:=cPassword
         .Range("B10:D23").Select
         Selection.Interior
        Pattern = xlSolid
        PatternColorIndex = xlAutomatic
        ThemeColor = xlThemeColorLight1
        TintAndShade = 0
        PatternTintAndShade = 0
        Active.Workbook.Save
        .PageSetup.PrintArea = "$B$3:$H$54"
        Application.Dialogs(xlDialogPrint).Show
        End With
         With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 4.99893185216834E-02
        .PatternTintAndShade = 0
        Active.Workbook.Save
        Cells.Locked = True
        Cells.FormulaHidden = False
        .Range("C5:D7,H11:H22,D34:D38,B46:H47,G56:H56,C60:C71,G77:H77,C81:C88,G93:H93,C94:C101").Locked = False
        .Protect Password:=cPassword, DrawingObjects:=False, Contents:=True, Scenarios:=False
        oWs.Parent.Save
End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,139
Office Version
  1. 365
Platform
  1. Windows
Maybe
VBA Code:
   With oWs
      .Unprotect Password:=cPassword
      With .Range("B10:D23").Interior
         .Pattern = xlNone
         .TintAndShade = 0
         .PatternTintAndShade = 0
      End With
      ActiveWorkbook.Save
      .PageSetup.PrintArea = "$A$3:$H$53"
      With .Range("B10:D23").Interior
         .Pattern = xlSolid
         .PatternColorIndex = xlAutomatic
         .ThemeColor = xlThemeColorLight1
         .TintAndShade = 0
         .PatternTintAndShade = 0
      End With
      .Range("D8").Value = .Range("D8").Value + 1
      Application.Dialogs(xlDialogPrint).Show
      .Cells.Locked = True
      .Cells.FormulaHidden = False
      .Range("C5:D7,H11:H22,H36:H40,D34:D38,B46:H47,G56:H56,C60:C71,G77:H77,C81:C88,G93:H93,C94:C101").Locked = False
      .Protect Password:=cPassword, DrawingObjects:=False, Contents:=True, Scenarios:=False
   End With
   oWs.Parent.Save
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,139
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,132,646
Messages
5,654,567
Members
418,142
Latest member
peterappiahkubi

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
Top