Split Code for Long Range Object

Eric G

New Member
Joined
Dec 21, 2017
Messages
47
In Excel, how do you split the VBA code for a long Range object?

To simplify my problem, let's say the following Range object is too long:
Code:
Set r1_text = Sheets("1").Range("E8:F17, E21:F70, I21:J70, C73:G87")

And I want the code to look like a list:
Code:
Set r1_text = Sheets("1").Range(" _
E8:F17, _
E21:F70,  _
I21:J70, _
C73:G87 _
")

However, when I move my cursor away from this line of code after hitting the enter key right after the first underscore, such as:
Code:
[COLOR=#ff0000]Set r1_text = Sheets("1").Range(" _
E8:F17, E21:F70, I21:J70, C73:G87")[/COLOR]

The code turns red, and a message box appears that says, "Compile error: Expected: list separator or )"

How do you make what I am trying to accomplish work? Suggestions?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You can't use the line continuation pattern for string literals. You'd need to do something like this:

Code:
Set r1_text = Sheets("1").Range( _
"E8:F17," & _
"E21:F70," & _
"I21:J70," & _
"C73:G87" _
)

WBD
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top