Take the code below; I am missing an End With however when it is compiled the error is: Next without For which is incorrect.
Option Explicit
Public Sub Payments()
Dim ws As Worksheet
'--> Format the original workbook
For Each ws In ThisWorkbook.Worksheets
With ws
.UsedRange.EntireColumn.Hidden = False
Next
End Sub
I have seen this behaviour with other errors too where the problem is not communicated properly. Why is this?
The error is not incorrect. From the interpreter’s point of view, the first problem that it encounters is that you have a
Nextinside aWithblock, which of course is an error.Compilers and interpreters (with the possible exception of the clang C compiler) are not good at guessing which of two possible errors is the one you “meant” to have.