Sub or Function not defined

excelos

Well-known Member
Joined
Sep 25, 2011
Messages
591
Office Version
  1. 365
Platform
  1. Windows
Hello

I get so frequently the error:
Sub or Function not defined

even for very simple things like one line functions:
Sub something()
Worksheet.Activate(...)
End Sub

Any idea?
Searching online did not give valuable hints and there seem to be several causes.

Thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
EX
VBA Code:
Sub something()
Worksheets("calc").Activate
End Sub
 
Upvote 0
Mmm thanks so this error is when something (that can be anything):
  • needs a specific input that is missing?
  • is not typed with the correct keyword to be recognised as internal VBA reserved keyword?
Because the error msg is kind of confusing by saying 'sub or function not defined' and it yellows the Sub... line instead of the Worksheets... line.
 
Upvote 0
I would like to see an actual example of code that returns this error for you, so we can better evaluate it.

Another source of issue could be typos (so maybe you are trying to use a keyword that is misspelled, so Excel thinks you are trying to call a Sub Procedure or Function).

I would highly recommend turning "Option Explicit" on, if you haven't already.
This forces you to declare all variables before using them, and helps greatly in error debugging.
If you have issues with typos, this will help catch those.
See: Option Explicit in Excel VBA
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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