VBA underscore trouble

Solved/Closed
Trowa - Jul 17, 2009 at 08:50 AM
 Trowa - Jul 21, 2009 at 06:52 AM
Hello,

I wrote a simple VBA code which is pretty long, so I want to use a underscore to continue on the next line.

Here is an example of the code:
Sub Mergeing()
Sheets("blad1").Range("A1:B1,A2: B2 ").Merge
End Sub

In the actual code I have a lot more cells I want to merge.

this is what I want to do:
Sub Mergeing()
Sheets("blad1").Range("a1:a3, _
b1: b3 ").Merge
End Sub

When I do this, I get a compiling error telling me to input a separator.

What am I doing wrong?
I thought a space followed by an underscore was enough to continue on the next line.

Please let me know what to do.

Best regards,
Trowa
Related:

4 responses

Excelguru Posts 261 Registration date Saturday April 11, 2009 Status Member Last seen June 21, 2011 307
Jul 20, 2009 at 01:17 AM
Hello Trowa

You have to close the active string and use & to club the two strings as given below

Sub Mergeing()
ActiveSheet.Range("a1:a3," & _
"b1: b3 ").Merge
End Sub
1
Thanks Excelguru,

Your code works but mine not. It seems I've created a string longer than 912 characters (error 1004).

Got any tips to work around this issue or maybe a tool to count the characters?

Thanks in advance,
Trowa
1
Excelguru Posts 261 Registration date Saturday April 11, 2009 Status Member Last seen June 21, 2011 307
Jul 20, 2009 at 11:22 PM
1
Hi Excelguru,

I already found that information, before I posted my question but I don't understand what microsoft wants me to do?

Since this might be of topic, I will post a new thread.
1