Break a long row of code

  • Thread starter Thread starter Otto Moehrbach
  • Start date Start date
O

Otto Moehrbach

Excel 2002, WinXP
I have a simple copy/paste line of code as this:
ThisRange.Copy ThatRange
This works fine. My problem is that "ThisRange" is actually a long string
to define the range. The same goes for "ThatRange". The result is that I
have a long line of code that stretches way off the screen. As I said, it
works fine, but it's hard to read.
I can usually break up a line of code with an underline character but I
have never been able to do that with a construct such as this.
Is there a way to put this construct on 2 lines? Thanks for your help Otto
 
Hi,
Using underscore will work:

ThisRange.Copy _
ThatRange

Alternatively do:

Set ThisRange= ........ ' may still need to break with _

Set ThatRange= ......... ' may still need to break with _


ThisRange.Copy ThatRange

HTH
 
Hi Otto

Sub Tester()
Dim sStr As String
Dim Rng As Range

sStr = "A1: A3 , A5: C7 , E10: F12 , G14: G16" & _
",I20:I22, L1:L3, M5:M7, O10:O12, Q15:Q17, Q22:Q24"
Set Rng = Range(sStr)
Rng.Select

MsgBox Rng.Address
End Sub
 
Idea 1: DIM new range variables Rng1 and Rng2 and set them = the long
strings, and then
Rng1.copy Rng2

Idea 2 - use "With"

With ThisRange
.copy Thatrange
end With


Set the long strings = separately dimmed range variables first, and build
your lines of code using the new variables:
set rng1 = ThisRange
set
Rng1
 
Otto,
To break up your lines of code you need to use space underscore " _".
If you omit the space it doesn't work.

Henry
 

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

Back
Top