PDA

View Full Version : Solved: Non-Contiguous Copy PasteSpecial



YellowLabPro
09-28-2007, 06:53 AM
I am hoping to combine the three ranges into one line of code, rather than three....
Permittable?

.Range("H4:U4" & ",Z4" & ",AC4").Copy
.Range("H6:U" & lrwSource & ",Z6:Z" & lrwSource & ", AC6:A" & lrwSource).PasteSpecial (xlPasteFormats)

Bob Phillips
09-28-2007, 07:07 AM
Don't think so, but why. Where is the problem, you only write it once.

YellowLabPro
09-28-2007, 07:13 AM
I was hoping to avoid this, which is six lines of code, rather than two if it were....


.Range("H4:U4").Copy
.Range("H6:U" & lrwSource).PasteSpecial (xlPasteFormats)
.Range("Z4").Copy
.Range("Z6:Z" & lrwSource).PasteSpecial (xlPasteFormats)
.Range("AC4").Copy
.Range("AC6:A" & lrwSource).PasteSpecial (xlPasteFormats)

rory
09-28-2007, 07:21 AM
Assuming you apply the format in the first place, couldn't you apply it to all the rows, then clear row 5?

Bob Phillips
09-28-2007, 07:43 AM
But again I ask why? That second block of code is much cleaner, readable and maintainable IMO than the other (even if it DID work).

YellowLabPro
09-28-2007, 08:36 AM
Rory,
Simply in this case no.

Bob- ok... no worries. As I move onward- I am looking for better ways to code. If in your opinion that this is the sound approach then I am good.

thanks

Bob Phillips
09-28-2007, 08:44 AM
Doug,

Never forget maintainability.Making the code easy to read and easy to maintain is very important, as in most typical applications, far more time is spent on maintenance than on development.

YellowLabPro
09-28-2007, 08:49 AM
Point is well taken.
But my code always looks like a little kid's term paper;

See Spot sit.
See Spot sleep.
See Spot eat.
Spot is a very boring dog, and sooner or later, Spot wants to run.

Norie
09-28-2007, 08:57 AM
Doug

And what's wrong with that?

Surely it's better to have code that's easy to follow and read rather than something that when looked at the first thought is WTF? :dunno

And you could find yourself having that thought if you return to code after a period.

:Thinkingo

Bob Phillips
09-28-2007, 10:54 AM
But Spot helped my girls learn to read. Einstein's paper on relativity was a tad difficult!

YellowLabPro
09-28-2007, 11:07 AM
All I can do is smile