I have been trying to sort this error and can't understand why it is happening. tried changing name of the sub and check many times to make sure the spelling is exactly the same but the error keeps ocurring and i can't understand why. Can someone help?
Asked
Active
Viewed 721 times
-1
-
3Please read: • [An image of your code is not helpful](http://idownvotedbecau.se/imageofcode) and • [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/a/284237/3219613) • Then [edit] and improve your question. – Pᴇʜ Mar 12 '20 at 10:16
-
To call a method in a standard module: `ModuleName.MethodName` – Kostas K. Mar 12 '20 at 10:20
-
I did read - https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface -help/expected-variable-or-procedure-not-module and https://www.ozgrid.com/forum/index.php?thread/15568-expected-variable-or-procedure-not-module-error/ - https://stackoverflow.com/questions/2804327/call-a-subroutine-from-a-different-module-in-vba and some other links i managed to get from searching google for the error but was unable to actually understand it and still not understanding. "Can someone help me" is my way of saying "can someone help me understanding what am I doing wrong" – Ruben Gaspar Mar 12 '20 at 10:32
1 Answers
1
You should not use the same name the module and the procedure. This will cause a conflict.
So if you Call SortDataSource
it will find the module name first and of course it cannot call a module (only a procedure or function within a module).
So if you use the same names you need to Call SortDataSource.SortDataSource
to make it call the procedure SortDataSource
inside the module SortDataSource
:
Syntax is like
Call ModuleName.MethodName(Argument1, Argment2)
or without Call
which is not needed.
ModuleName.MethodName Argument1, Argment2
But I highly recommend not to use the same name for a module and a procedure. As you can see it can cause errors that can easily be avoided by choosing different names.

Pᴇʜ
- 56,719
- 10
- 49
- 73
-
2Quick question, doesnt `ModuleName.MethodName Argument1, Argument2` give an error? shouldn't it be `ModuleName.MethodName(Argument1, Argument2)` Not tryna be rude or anything. was just wondering :) – Nemoko Mar 12 '20 at 10:27
-
-
-
Thank you. so why does it work when i use the other call without specifying method name "Call RowDelete" but it does not work with "Call RowSort" and I have to do the Call ModuleName.MethodName Argument1, Argment2 for that one? – Ruben Gaspar Mar 12 '20 at 10:39
-
@RubenGaspar Don't get your question. What exactly works and what doesn't? Please be more precise. If you need to post more code please edit your original question add the code there and leave a comment. – Pᴇʜ Mar 12 '20 at 10:41
-
Note that if the name of a method is unique in VBA you just need to call it by it's name `Call MyName` but if the name is not unique and there also exists a module with the exact same name, or the same method name exists in different modules then you need to specify the module name. – Pᴇʜ Mar 12 '20 at 10:46
-
Nevermind the last question, now i understand what i did wrong. thank you for your help :) – Ruben Gaspar Mar 12 '20 at 10:57