+ Reply to Thread
Results 1 to 16 of 16

Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

  1. #1
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Hi,
    How do you acheive this in 1 vba macro at the same time:
    1. copy/paste visible cells only from Sheet1 to Sheet2?
    2. copy/paste multiple different ranges?

    See Attachment.
    Attached Files Attached Files
    Last edited by Aaeijh; 02-12-2018 at 12:26 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    It is unclear if you are attempting to copy only rows that are not hidden, or if you are trying to copy on rows where cells are not blank. Your example indicates that it is the latter, but you need to verify that.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Clarification: only copy rows that are not hidden.
    Thanks,

  4. #4
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Take a look at this: https://msdn.microsoft.com/en-us/vba...s-method-excel

    Specifically xlCellTypeVisible. You then treat it like any other range (ie: copy, paste, delete, etc)
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  5. #5
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    ok, after reading the microsoft article, I created this vba macro, but get an error:

    Please Login or Register  to view this content.
    Seems to be in the right direction, just cant pinpoint the source of the error,


    See Attachment.
    Attached Files Attached Files

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Well, yeah, you didn't copy, only paste. That will error every time.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Thanks for pointing that out,

    Here's the updated code, including the "Copy"

    Please Login or Register  to view this content.
    Unfortunately, its generating an error when running the macro.
    • With Range("rGroup1TitleAndRows").Copy ---> ERROR: Method 'Range of Object' _Global Failed.
    • With rGroup1TitleAndRows.Copy ---> ERROR: Runtime 1004, That command cannot be used on multiple selections.

    Any additional thoughts on how to copy and paste a combination of ranges?
    Last edited by Aaeijh; 02-13-2018 at 09:59 AM.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    See if replacing this
    Please Login or Register  to view this content.
    With this

    Please Login or Register  to view this content.
    will work. I didn't test it.

  9. #9
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Once again, thanks for the reply,

    Here's the new code:

    Please Login or Register  to view this content.
    But this error comes up:

    macro-error.jpg


    Let me know how I'm doing this wrong,?!,.


    Thanks,
    Last edited by Aaeijh; 02-13-2018 at 10:55 AM.

  10. #10
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,257

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    if not hidden cell
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    daboho,

    Thanks for this,!

    The code works!, but it copy/paste every visible rows,

    code-vs-desired-result.jpg

    In addition to copy/paste only the visible rows, we're trying to select a specific combination of ranges...

    ie - programattically only select what's in blue

    sheet1.jpg

    Any thoughts?
    Last edited by Aaeijh; 02-13-2018 at 11:56 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,257

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    you talk that is hidden row
    if hidden row not to copy using specialcells(12)

  13. #13
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Its a combination of both:

    1. combine "specific ranges" from different rows that are not consecutive
    2. only copy/paste visible rows

  14. #14
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Quote Originally Posted by Aaeijh View Post
    Once again, thanks for the reply,

    Here's the new code:

    Please Login or Register  to view this content.
    But this error comes up:

    Attachment 560914


    Let me know how I'm doing this wrong,?!,.


    Thanks,
    Sorry about that, had a glitch when I posted and did not fix it properly. Here is replacement code.
    Please Login or Register  to view this content.

  15. #15
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Quote Originally Posted by Aaeijh View Post
    Its a combination of both:

    1. combine "specific ranges" from different rows that are not consecutive
    2. only copy/paste visible rows
    To use the SpecialCells(xlCellTypeVisible) function and get desired results, the rows you do not want to copy must be hidden, not blank and not camoflauged by changing the font to white.
    VBA can still see when a range is not hidden even if the human eye sees it as empty.

  16. #16
    Registered User
    Join Date
    02-01-2018
    Location
    London, England
    MS-Off Ver
    MS Office 2007
    Posts
    10

    Re: Howto Copy/Paste Visible Only, Multi-Range, from Sheet1 to Sheet2

    Hi JLGWhiz,

    Slightly modified your code to make it work, but it doesn't achieve the desired outcome,

    code-vs-desired-outcome2.jpg

    Maybe its impossible to copy/paste from multiple range, idk,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy/Paste Data from Sheet1 to Sheet2
    By h.noor in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-11-2015, 11:39 PM
  2. Replies: 6
    Last Post: 07-25-2013, 02:58 PM
  3. [SOLVED] Copy Range of data from sheet1 and sheet2 paste it in sheet3
    By hassan khansa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2013, 05:55 AM
  4. Copy Range of data from sheet1 and sheet2 paste it in sheet3
    By hassan khansa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2013, 05:47 AM
  5. Replies: 4
    Last Post: 03-17-2013, 05:58 AM
  6. [SOLVED] Copy and Paste Entire Row from Sheet1->Sheet2 based on text string match in Sheet1 Row
    By dmlovic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-17-2012, 08:42 AM
  7. Copy 3 cells from sheet1 then paste to sheet2
    By Christeen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2011, 09:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1