Consulting

Results 1 to 11 of 11

Thread: Solved: Non-Contiguous Copy PasteSpecial

  1. #1

    Solved: Non-Contiguous Copy PasteSpecial

    I am hoping to combine the three ranges into one line of code, rather than three....
    Permittable?
    [VBA]
    .Range("H4:U4" & ",Z4" & ",AC4").Copy
    .Range("H6:U" & lrwSource & ",Z6:Z" & lrwSource & ", AC6:A" & lrwSource).PasteSpecial (xlPasteFormats)
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Don't think so, but why. Where is the problem, you only write it once.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    I was hoping to avoid this, which is six lines of code, rather than two if it were....

    [VBA]
    .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)
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Assuming you apply the format in the first place, couldn't you apply it to all the rows, then clear row 5?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    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
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    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.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  9. #9
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    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?

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


  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    But Spot helped my girls learn to read. Einstein's paper on relativity was a tad difficult!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    All I can do is smile
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •