VBA underscore trouble [Solved/Closed]

Trowa - Jul 17, 2009 at 08:50 AM - Latest reply:  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
See more 

4 replies

Best answer
Excelguru 261 Posts Saturday April 11, 2009Registration date June 21, 2011 Last seen - Jul 20, 2009 at 01:17 AM
1
Thank you
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

Thank you, Excelguru 1

Something to say? Add comment

CCM has helped 1703 users this month

Best answer
1
Thank you
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

Thank you, Trowa 1

Something to say? Add comment

CCM has helped 1703 users this month

Best answer
Excelguru 261 Posts Saturday April 11, 2009Registration date June 21, 2011 Last seen - Jul 20, 2009 at 11:22 PM
1
Thank you
Info from Micorsoft
http://support.microsoft.com/kb/818808

Thank you, Excelguru 1

Something to say? Add comment

CCM has helped 1703 users this month

Best answer
1
Thank you
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.

Thank you, Trowa 1

Something to say? Add comment

CCM has helped 1703 users this month