Compile error: Next without For || VBA

Every For statement with a body must have a matching Next, and every If-Then statement with a body must have a matching End If. Example: You have part of the body of your If statement inside your For i loop, and part of it outside. It has to be either ALL inside or ALL outside. …

Read more

macro run-time error ‘9’: subscript out of range

“Subscript out of range” indicates that you’ve tried to access an element from a collection that doesn’t exist. Is there a “Sheet1” in your workbook? If not, you’ll need to change that to the name of the worksheet you want to protect.

How to detect if user select cancel InputBox VBA Excel

If the user clicks Cancel, a zero-length string is returned. You can’t differentiate this from entering an empty string. You can however make your own custom InputBox class… EDIT to properly differentiate between empty string and cancel, according to this answer. Your example Would tell the user they canceled when they delete the default string, …

Read more

Test or check if sheet exists

Some folk dislike this approach because of an “inappropriate” use of error handling, but I think it’s considered acceptable in VBA… An alternative approach is to loop though all the sheets until you find a match.