Line numbers

M

Microsoft Forum

Hi all,

Is it possible to view line numbers of a VBA subroutine on screen and in
printing? Thanks a lot.

Frederick Chow
Hong Kong.
 
H

Harlan Grove

Microsoft Forum said:
Is it possible to view line numbers of a VBA subroutine on screen and in
printing? Thanks a lot.

Not in Office's Visual Basic Editor. If you want to have positional
indicators in code that you can find in the Visual Basic Editor, then you'd
need to add comments to your code that provide such.
 
P

Peter T

Hi Frederick,

Sub test()
1 Dim v
10 v = 2
20 If v = 4 Then
30 MsgBox "Bye"
40 Exit Sub
50 End If
60 v = 4
70 GoTo 20
End Sub

Try pasting old code without numbers to Col B on your worksheet, put
appropriate numbers in Col A, paste all back to the vbe.

Seems if you number some lines, any lines that are not numbered are ignored,
including Dim statements.

Regards,
Peter
 
T

Tom Ogilvy

Sub test()
1 Dim v
10 v = 2
20 If v = 4 Then
MsgBox "Bye"
40 Exit Sub
50 End If
60 v = 4
70 GoTo 20
End Sub

worked fine and the msgbox line is not numbered.
 
P

Peter T

Hi Tom,
worked fine and the msgbox line is not numbered.

So it does. I was sure in previous testing unnumbered lines were ignored, as
if they were commented. Normally I would have to put this down to loosing my
senses, but in this case I'll blame it on a late night!

FWIW another observation, line numbers do not need to be in any sort of
order.

regards,
Peter
 
M

Myrna Larson

Not true. The only lines that VBA treats as comments are those that start with
the REM command or an apostrophe.
 
M

Microsoft Forum

Microsoft Forum said:
Hi all,

Is it possible to view line numbers of a VBA subroutine on screen and in
printing? Thanks a lot.

Frederick Chow
Hong Kong.
 
P

Peter T

Hi Myrna,

Absolutely. It was something I thought I noticed for the first time just
before posting, but not so as Tom pointed out. You may have misinterpreted
my "So it does." as contradicting Tom, rather than conceding as was
intended.

Regards,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top