"Expected End Sub Error"?

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
WHen I compile my VBA project, I get an error with this procedure. It won't even start the procedure, giving me the error "Expected End Sub", with the worksheet reference highlighted. (hightlighted below in blue)
I'm not sure what that error means ... I do have an "End Sub"
Rich (BB code):
Sub open_permit()
    Application.ScreenUpdating = False
    strpath = "D:/WSOP 2020/permit_data.xlsx"
    Workbooks.Open strpath
    Set wb_permit = Workbooks("permit_data.xlsx")
    Set ws_permit = wb_permit.Worksheets("Permit_Data")
    Set ws_cust = wb_permit.Worksheets("Customer_Default")
    If ws_permit.AutoFilterMode Then ws_permit.AutoFilterMode = False
    lrow = ws_permit.Cells(ws_permit.Rows.Count, "A").End(xlUp).Row
    Set rngPermit = ws_fac.Range("A1:BO" & lrow)
    lrow = ws_cust.Cells(ws_cust.Rows.Count, "A").End(xlUp).Row
    Set rngCust = ws_cust.Range("A1:AG" & lrow)
    wb_permit.Windows(1).Visible = False
    Application.ScreenUpdating = True
    ws_front.Unprotect
    With ws_front.Cells(5, 1)
        .Value = "Permit Data"
        .Font.Color = RGB(24, 160, 35) 'green
    End With
    ws_front.Pictures("hidden3").Visible = True
    ws_front.Protect
End Sub
 
"Option Explicit" needs to be placed at the very top of your code (the very first line), before your Public variable declarations.
Then your procedure still needs some clean-up, as you still have undeclared variables in it, like "svcDate" and "wb_data".

Please go though and fix all of these, then re-post all the code from the procedure.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Does option explicit need to go into every procedure, or just once at the top of each module and object code? When I run Compile VBA Code, I expect it will catch all the variables being used and not declared correct? I dop that and it only catches one error.

svcDate and wb_data are publically declared in this module which is called from within the workbook open code.

Code:
Option Explicit
Public wb_dia As Workbook
Public ws_template As Worksheet
Public ws_lists As Worksheet
Public ws_front As Worksheet
Public ws_staff As Worksheet
Public wb_data As Workbook
Public ws_master As Worksheet

Public rngFac As Range
Public rngFac3 As Range
Public rngDTemp As Range
Public rngFTemp As Range
Public rngCTemp As Range
Public rngTTemp As Range
Public rngPTemp As Range
Public rngSvc As Range

Public mbevents As Boolean
Public svcCnt As Double
Public svcDate As Date
Public shp As Shape
Public svcCol As Double
Public svcRow As Double
Public svcRid As Double
Public RID As String

Sub ini1()
'Stop
    Set wb_dia = Workbooks("Diamond_Test.xlsm")
    Set ws_template = wb_dia.Worksheets("template")
    Set ws_lists = wb_dia.Worksheets("lists")
    Set ws_front = wb_dia.Worksheets("front")
    Set ws_staff = wb_dia.Worksheets("staff")
    Set rngDTemp = ws_template.Range("B1:AB44")
    Set rngFTemp = ws_template.Range("AG1:BG44")
    Set rngCTemp = ws_template.Range("BL1:CL44")
    Set rngTTemp = ws_template.Range("CQ1:DQ44")
    Set rngSvc = ws_lists.Range("A2:C51")
    Set rngFac = ws_lists.Range("E1:E" & ws_lists.Cells(ws_lists.Rows.Count, "E").End(xlUp).Row)
    Set rngFac3 = ws_lists.Range("E1:G" & ws_lists.Cells(ws_lists.Rows.Count, "E").End(xlUp).Row)
End Sub
 
Upvote 0
Wow, you just have a ton of code everywhere, making calls to variables and code in other modules. It makes it very hard to determine what might be going on, especially when it isn't an obvious error.
It could be corruption, but it could also be something else. Without having access to all of it, I don't think we can really say. I don't see anything that sticks out as obviously wrong.
 
Upvote 0
Thanks Joe, I just created a new workbook and copied over over the code to it. The new version works fine with the exact same code, so safe to assume something got corrupted with the file. Thanks for your help.
 
Upvote 0
Excellent. Glad you got it working.
I guess corruption makes sense, as the lines it was highlighting didn't make any sense, since you were already using similar lines.
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,324
Members
453,032
Latest member
Pauh

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