on workbook open error

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
Hi Guys I am getting this error when my workbook opens. This started happening when we upgraded our office to 2016

else without if

and it brings me here

If ActiveWorkbook.name = "Roof System.xlsm" Then Range("J1").Formula = "=today()"
Else
Exit Sub
End If

not sure why this is happening... any ideas?... essentially I want this cel left alone unless the workbook is named Roof System.xlsm
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Just get rid of the Else & the Exit Sub lines
 
Upvote 0
What Fluff said (if you don't have any code after if statement). Or, move the statement(s) in then block to a new line.

Reason: IF-THEN has two syntaxes - one line and multiline.

One line IF-THEN (doesn't need END IF keywords)
Code:
IF conditions THEN code ELSE code
Multiline IF-THEN (needs END IF keywords to end)
Code:
IF conditions THEN
    code
ELSE
    code
END IF
 
Last edited:
Upvote 0
These errors can occur because the Ifs/EndIfs are wrong anywhere in the code. As well as Withs/EndWiths and Do/Whiles Loop/Untils or any kind of control block.

You should post the whole code.

Note: and, as noted above, there are two syntaxes, one for single line and one for multiline if statements!! Good catch.
 
Last edited:
Upvote 0
As posted above, remove the End If as well
 
Upvote 0
This is nothing to do with the upgrade, try this.
Code:
If ActiveWorkbook.name = "Roof System.xlsm" Then Range("J1").Formula = "=today()"
Or this.
Code:
If ActiveWorkbook.name = "Roof System.xlsm" Then 
    Range("J1").Formula = "=today()"
Else
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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