Macro Error

ghrek

Active Member
Joined
Jul 29, 2005
Messages
426
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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You will need an End With after each of your With sections.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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