Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default How to separate on very long line of code in VBA

Hello,
I'm trying to figure out how to put a single command onto several
lines. This is necessary when the line of code is much wider than the
editing screen. I see in examples that people use _ to separate lines
of code. When I try this my code turns red and VBA tells me I have an
error. Can someone please explain how this is done.

thanks,
Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default How to separate on very long line of code in VBA

"Andrew" wrote in message
...
Hello,
I'm trying to figure out how to put a single command onto several
lines. This is necessary when the line of code is much wider than the
editing screen. I see in examples that people use _ to separate lines
of code. When I try this my code turns red and VBA tells me I have an
error. Can someone please explain how this is done.

thanks,
Andy



you need a space before the _

--
Clif McIrvin

(clare reads his mail with moe, nomail finds the bit bucket :-)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default How to separate on very long line of code in VBA

"Clif McIrvin" wrote in message
...
"Andrew" wrote in message
...
Hello,
I'm trying to figure out how to put a single command onto several
lines. This is necessary when the line of code is much wider than
the
editing screen. I see in examples that people use _ to separate
lines
of code. When I try this my code turns red and VBA tells me I have
an
error. Can someone please explain how this is done.

thanks,
Andy



you need a space before the _



from the VBA help glossary:
<quote
line-continuation character
The combination of a space followed by an underscore ( _) used in the
development environment to extend a single logical line of code to two
or more physical lines. However, you can't use a line-continuation
character to continue a line of code within a string expression.</quote

If the preceeding space wasn't you problem, did you enter a <cr after
the underscore?

From the VBE window, press F1 for help and search for line continuation
for more information.

--
Clif McIrvin

(clare reads his mail with moe, nomail finds the bit bucket :-)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default How to separate on very long line of code in VBA

On Nov 5, 7:50*am, "Clif McIrvin" wrote:
"Clif McIrvin" wrote in message

...



"Andrew" wrote in message
....
Hello,
I'm trying to figure out how to put a single command onto several
lines. *This is necessary when the line of code is much wider than
the
editing screen. *I see in examples that people use _ to separate
lines
of code. *When I try this my code turns red and VBA tells me I have
an
error. *Can someone please explain how this is done.


thanks,
Andy


you need a space before the _


from the VBA help glossary:
<quote
line-continuation character
The combination of a space followed by an underscore ( _) used in the
development environment to extend a single logical line of code to two
or more physical lines. However, you can't use a line-continuation
character to continue a line of code within a string expression.</quote

If the preceeding space wasn't you problem, did you enter a <cr after
the underscore?

From the VBE window, press F1 for help and search for line continuation
for more information.

--
Clif McIrvin

(clare reads his mail with moe, nomail finds the bit bucket :-)


Thanks for the tip. I was trying to break a string. That explains
it.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default How to separate on very long line of code in VBA

"Andrew" wrote in message
...
On Nov 5, 7:50 am, "Clif McIrvin" wrote:
"Clif McIrvin" wrote in message

...



"Andrew" wrote in message
...
Hello,
I'm trying to figure out how to put a single command onto several
lines. This is necessary when the line of code is much wider than
the
editing screen. I see in examples that people use _ to separate
lines
of code. When I try this my code turns red and VBA tells me I have
an
error. Can someone please explain how this is done.


thanks,
Andy


you need a space before the _


from the VBA help glossary:
<quote
line-continuation character
The combination of a space followed by an underscore ( _) used in the
development environment to extend a single logical line of code to two
or more physical lines. However, you can't use a line-continuation
character to continue a line of code within a string
expression.</quote

If the preceeding space wasn't you problem, did you enter a <cr after
the underscore?

From the VBE window, press F1 for help and search for line
continuation
for more information.

--
Clif McIrvin

(clare reads his mail with moe, nomail finds the bit bucket :-)


Thanks for the tip. I was trying to break a string. That explains
it.
...........
You can break a string by using the & concatenation operator:

strLongValue = "First part of a very long string" & _
"second part of a very long string"

Glad you got it sorted!


--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default How to separate on very long line of code in VBA

On Nov 6, 1:11*pm, Andrew wrote:
On Nov 5, 7:50*am, "Clif McIrvin" wrote:





"Clif McIrvin" wrote in message


...


"Andrew" wrote in message
....
Hello,
I'm trying to figure out how to put a single command onto several
lines. *This is necessary when the line of code is much wider than
the
editing screen. *I see in examples that people use _ to separate
lines
of code. *When I try this my code turns red and VBA tells me I have
an
error. *Can someone please explain how this is done.


thanks,
Andy


you need a space before the _


from the VBA help glossary:
<quote
line-continuation character
The combination of a space followed by an underscore ( _) used in the
development environment to extend a single logical line of code to two
or more physical lines. However, you can't use a line-continuation
character to continue a line of code within a string expression.</quote


If the preceeding space wasn't you problem, did you enter a <cr after
the underscore?


From the VBE window, press F1 for help and search for line continuation
for more information.


--
Clif McIrvin


(clare reads his mail with moe, nomail finds the bit bucket :-)


Thanks for the tip. *I was trying to break a string. *That explains
it.- Hide quoted text -

- Show quoted text -

Andrew

If it's a string you don't need to have everything on one line, you
can try something like this which is along the lines of Cliff's post.

strSQL = strSQL & "SELECT Field1, Field2, Field3, Field4 "
strSQL = strSQL & "FROM table1 "
strSQL = strSQL & "WHERE ID = 3 AND Field2 Like 'Something*' "

That's an example for an SQL statement but you can use the same idea
for any string.

One advantage of using this method is that if you are creating a
string for something like an SQL query or
perhaps a database connection is that you can comment out lines,
change lines, add lines etc

That should make it far easier to debug if you are getting errors or
the string just isn't appearing as you want it.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How separate a Long text by first space? ldiaz Excel Discussion (Misc queries) 4 September 18th 08 11:01 PM
Looking for code to separate one line of text into multiple lines in Excel [email protected] Excel Worksheet Functions 1 February 13th 07 12:59 AM
Breaking up long line of code doesn't work Hector Fernandez Excel Programming 13 December 18th 06 03:00 PM
one VERY LONG line moussant Excel Discussion (Misc queries) 7 November 11th 06 02:36 PM
To separate two line in a line chart TRUST Charts and Charting in Excel 2 October 20th 06 05:18 AM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"