How to separate one line into two (or more) in coding?

H

Howard

Sometimes it's inconvenient to keep a long line in coding,
I prefer to have multiple lines. How to do so?
 
H

Howard

Rob,

Thanks for your fast response, but I still can't make it
work.

I have the the following code:
MsgBox "A message to the world."
If I change it to three lines:
MsgBox_
_"A message"_
_"to the world."
It's not working. What should I do?

Thanks in advance.
Howard
 
G

Guest

Hi Howard

I could be wrong, but I think what you want is a 'carriage return' in the text of your message box

It would look like this
MsgBox "A message" & Chr(13) & "to the world!

The displayed message box would look like

A messag
to the world

Use Rob's instruction when the VBA code line
gets longer than you want to fit
into the window and you don't want to have to use the horizontal scroll bar to see how the entire line reads
just to understand it

Rick..

----- Howard wrote: ----

Rob

Thanks for your fast response, but I still can't make it
work.

I have the the following code
MsgBox "A message to the world.
If I change it to three lines
MsgBox
_"A message"
_"to the world.
It's not working. What should I do

Thanks in advance
Howar
 
D

Douglas J. Steele

When you split a string, you need to use & to concatenate the parts
together:

MsgBox _
"A message" & _
"to the world."

(and you must do it that way: terminating each string on its line and
concatenating it to the string on the next line)

Also, make sure there's a space in front of the underscore.
 
V

Van T. Dinh

same as Doug but add a space character after "message" (or before "to") to
separate the words "message" & "to".
 

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