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
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
Attach a workbook showing what the data looks like before and after.
BSB
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.
Regards,
Stephen
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.
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
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![]()
Last edited by k1dr0ck; 08-28-2022 at 03:06 AM.
@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
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
just in case anyone is interested should have been
![]()
Do While y < x
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks