Consulting

Results 1 to 12 of 12

Thread: How to copy two non-contiguous cells

  1. #1

    How to copy two non-contiguous cells

    I want to copy this to the clipboard:
    F7and F9
    This line copies F7 through F9
    [vba]
    Range("F9" & ",F7").Copy
    [/vba]

    thx
    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
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA] Range("F7,F9").Copy Range("J10")
    [/VBA]
    Don't forget the Macro recorder!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Good Day Malcolm,
    Good point about the recorder.
    But this is slightly different. Copying the non-contiguous cells to a sheet works fine, but not to the windows clipboard. It copies and pastes a contiguous range- F7, F8, & F9 to the windows clipboard.
    So when I paste I get data from F8 I do not want in it.

    The only way I have figured out how to handle this is:

    [VBA]
    Range("F7,F9").Copy Range("IV1")
    Range("IV1").Cut
    Range("IV1").Copy Range("IV3")
    Range("IV1").Delete Shift:=xlShiftUp
    Range("IV1:IV2").Copy
    [/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
    Doug,
    Range("F7,F9").Copy works for me.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Rory,
    The copy works,
    but paste it to a notepad file, you will see it pastes the contents of f7,f8, and f9, not just f7 and f9
    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!

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Oh OK. Is that actually your destination?
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    More or less.
    Not to open a can of worms here, but it is to copy two email addresses to my email program send to field, so the clipboard is the copy to location.
    SendMail method in VBA will only work up until a point w/ AOL.
    I can either get the subjet or the send to address, but not both.
    So I chose the subject.
    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!

  8. #8
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Do you have Outlook? You can set that up to work with AOL's IMAP email.
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    I do have Outlook.
    You will have to give me some idea of IMAP.... and what is involved.
    thanks for the extra help on this, being out of scope... ;-)
    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!

  10. #10
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    I don't have the details here, but they should be on the AOL website. It's not that hard to set up as I recall (been a while since I actually used my AOL account to send any email!)
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Interesting Doug.
    You can simplify your intermediate step a bit though
    [VBA]Range("E5, E9").Copy Range("IV1")
    Range("IV1").CurrentRegion.Copy
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    Thanks Malcolm,
    sorry for the delay- did not get a notice anything had been updated. I just happened to check in...

    cheers
    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
  •