PDA

View Full Version : line number in module



lior03
02-08-2006, 11:05 PM
hello
if i have a lenghty module,is it possible through vba to go to a specific line.
namely-in active module go to line 100 or 150.if the line do not exist then go to the last line.
thanks

Bob Phillips
02-09-2006, 01:53 AM
hello
if i have a lenghty module,is it possible through vba to go to a specific line.
namely-in active module go to line 100 or 150.if the line do not exist then go to the last line.
thanks

If you have to have goto's why not add a lab el and goto that?

lior03
02-09-2006, 02:37 AM
hello

please explain.

Marcster
02-09-2006, 02:52 AM
Does this article help you?:
Has text regarding the goto command.

http://www.vbaexpress.com/forum/articles.php?action=viewarticle&artid=52

Marcster.

Bob Phillips
02-09-2006, 03:06 AM
hello

please explain.

something like


If myVal = 17 Then
Goto val_17_Cond
Else
'more code
...
...
val_17_cond:
'carry on code

lior03
02-09-2006, 03:47 AM
so if i am at module 17 and wants to tell excel to go to line 117 in that module.how do i do it through vba?

Bob Phillips
02-09-2006, 03:57 AM
so if i am at module 17 and wants to tell excel to go to line 117 in that module.how do i do it through vba?

You can only goto a line number in the same procedure, if it is outside that procedure, you can't do it. This is also true with labels.

What exactly are you trying to do, there must be a better way?

lior03
02-09-2006, 04:13 AM
hello xld

i saw at http://www.bygsoftware.com/bygtools/bygtools_documentation.htm
this example
7.2. Go to

Go to a specific line number in the current module. Especially useful in large modules with several thousand lines of code.


this i believe could be doen with a listbox by which you enter line number.
could it be doen by a macro .or maybe a userform as it is shown in that site
yours
moshe

Bob Phillips
02-09-2006, 05:10 AM
So why not just download Andy's addin and you have it?

It will mean you need to add line numbers to your code, or at least to specified lines so as to be able to goto them. Personally, I would add labels and provide a facility to jump to those labels.

But as always, it only works in the current procedure, and if you have a procedure with thousands of lines, why?