VBA underscore trouble [Solved/Closed]

Report
-
 Trowa -
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

4 replies

Posts
261
Registration date
Saturday April 11, 2009
Status
Member
Last seen
June 21, 2011
307
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
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2836 users have said thank you to us this month

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
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2836 users have said thank you to us this month

Posts
261
Registration date
Saturday April 11, 2009
Status
Member
Last seen
June 21, 2011
307
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2836 users have said thank you to us this month

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
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2836 users have said thank you to us this month