+ Reply to Thread
Results 1 to 9 of 9

copy non contiguous cells with values and paste in another sheet

Hybrid View

k1dr0ck copy non contiguous cells... 08-27-2022, 05:50 AM
BadlySpelledBuoy Re: copy non contiguous cells... 08-27-2022, 06:55 AM
swaatacba Re: copy non contiguous cells... 08-27-2022, 07:08 AM
beyond Excel Re: copy non contiguous cells... 08-27-2022, 10:08 AM
JEC. Re: copy non contiguous cells... 08-27-2022, 10:16 AM
k1dr0ck Re: copy non contiguous cells... 08-28-2022, 03:03 AM
k1dr0ck Re: copy non contiguous cells... 09-04-2022, 03:20 AM
k1dr0ck Re: copy non contiguous cells... 09-05-2022, 03:32 AM
k1dr0ck Re: copy non contiguous cells... 09-08-2022, 06:21 AM
  1. #1
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    copy non contiguous cells with values and paste in another sheet

    hi,

    i would like to copy non contiguous (in different rows and columns) cells with data in sheet 1 and paste into a list in sheet 2 starting at A1

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: copy non contiguous cells with values and paste in another sheet

    Attach a workbook showing what the data looks like before and after.

    BSB

  3. #3
    Forum Contributor
    Join Date
    07-21-2021
    Location
    Norfolk, UK
    MS-Off Ver
    Excel 2003, 2007, 2013, 2019
    Posts
    215

    Re: copy non contiguous cells with values and paste in another sheet

    I tried to record a macro for copying non-contiguous cells, but got the following error message. In Excel 2013, at least this is a non-starter.
    Attached Images Attached Images
    Regards,

    Stephen

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: copy non contiguous cells with values and paste in another sheet

    Hello.
    To be able to copy discontiguous cells:

    - All cells must be in the same row, or
    - All cells must be in the same column

    It follows that if the selection has a diversity of rows or columns, the copy is not made.

  5. #5
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: copy non contiguous cells with values and paste in another sheet

    Maybe?

    Sub jec()
     Dim sq(), ar, x As Long, j As Long, jj As Long
     ar = Sheets(1).UsedRange
     
     For j = 1 To UBound(ar)
       For jj = 1 To UBound(ar, 2)
         If ar(j, jj) <> "" Then
           ReDim Preserve sq(x)
           sq(x) = ar(j, jj)
           x = x + 1
         End If
       Next
     Next
    
     Sheets.Add.Cells(1).Resize(x) = Application.Transpose(sq)
    End Sub

  6. #6
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    Re: copy non contiguous cells with values and paste in another sheet

    hi,

    thanks for the replies, i used JEC's code it works

    FYI
    attached my sample workbook
    sheet 1 is before
    sheet 2 is after

    @jec will add rep after I add rep to a different user, before this post apparently you were my last rep recipient
    Attached Files Attached Files
    Last edited by k1dr0ck; 08-28-2022 at 03:06 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    Re: copy non contiguous cells with values and paste in another sheet

    @jec


    how can i display the result in a body of an email instead?
    I'm trying below and it just says type mismatch

    .body = "Hi" & vbNewLine & vbNewLine & sq

  8. #8
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    Re: copy non contiguous cells with values and paste in another sheet

    found a code tried it but it says subscript out of range

    Sub email()
    
    Dim sq(), ar, x As Long, j As Long, jj As Long
    Dim y, sBody
    
     ar = Sheets(1).UsedRange
     
     For j = 1 To UBound(ar)
       For jj = 1 To UBound(ar, 2)
         If ar(j, jj) <> "" Then
           ReDim Preserve sq(x)
           sq(x) = ar(j, jj)
           x = x + 1
         End If
       Next
     Next
    
            sBody = "Hi,"
            Do While y <= x
              sBody = sBody & vbNewLine & sq(y)
              y = y + 1
            Loop
        
        With CreateObject("outlook.application").createitem(0)
           .To = "my@email.com"
           .Subject = "My subject"
           .body = sBody
           '.Attachments.Add
           .display '.send
        End With    
    
    End Sub

  9. #9
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    Re: copy non contiguous cells with values and paste in another sheet

    just in case anyone is interested should have been

    Do While y < x

+ 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. [SOLVED] Consolidate (Copy/Paste) Non-Contiguous Cells from Multiple Sheets to Single One
    By gophins in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2021, 03:51 PM
  2. [SOLVED] Copy / Paste Non-Contiguous Cells - User Selected
    By Logit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2017, 10:24 AM
  3. Copy contiguous columns and paste as non-contiguous
    By absconditus in forum Excel General
    Replies: 1
    Last Post: 12-29-2014, 03:17 AM
  4. Copy and paste special values for non contiguous ranges
    By ndelta34 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2014, 06:51 AM
  5. [SOLVED] copy and paste from contiguous cells to non-contiguous cells using the = function
    By shameus in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-05-2013, 06:48 PM
  6. Copy non-contiguous cells from one sheet to another
    By Grizz in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2010, 11:44 PM
  7. Copy and Paste an array (contiguous & non contiguous ranges)
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2010, 09:17 AM

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