Forum Discussion
Excel VBA Reference Line Where Error Occurs
If your code doesn't have line numbers, VBA doesn't "know" the line number where an error occurs...
HansVogelaarI appologize, Let me clarify. The attached pic shows Line reference data that VBA shows when working in each module. What I'm saying is there should be a way to reference this line when errors occur.
- HansVogelaarJan 29, 2021MVP
Yes, I know, but that information is not exposed to the programmer when an error occurs.
There is an obscure function Erl that returns the line number of an error, but if you haven't actually added line numbers, Erl always returns 0.
The Err object doesn't provide line number information... 😞
- heylookitsmeJan 29, 2021Iron ContributorThat information is not exposed to the programmer when an error occurs.
It should be. That would provide a great way for programmers to get specific error details which would help them debug errors much faster. I see this having huge potential if it were available.- jlansteadFeb 14, 2023Copper Contributor
https://www.fmsinc.com/free/newtips/VBA/ErrorHandling/LineNumber.html
First, you must number the lines and then reference the line number that causes the error using ERL.
You can find an example in the link above.