Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How separate a Long text by first space? | Excel Discussion (Misc queries) | |||
Looking for code to separate one line of text into multiple lines in Excel | Excel Worksheet Functions | |||
Breaking up long line of code doesn't work | Excel Programming | |||
one VERY LONG line | Excel Discussion (Misc queries) | |||
To separate two line in a line chart | Charts and Charting in Excel |