View Single Post
 
Old 05-17-2023, 09:50 PM
14spar15 14spar15 is offline Windows 7 64bit Office 2010 64bit
Advanced Beginner
 
Join Date: Mar 2011
Posts: 97
14spar15 is on a distinguished road
Default Copy and Paste certain columns from selected rows.

Hello, From “Sheet1” I want to be able to select random rows and when the macro is run columns B, C, E, G and J from the selected rows will be pasted into the “Paste” sheet. I found this code in a forum that seems to work except for they wanted Rows A, B and E.

Sub Macro1()
Dim rng As Range
For Each rng In Selection.Areas
Union(rng.Resize(, 2), rng.Resize(, 1).Offset(, 4)).Copy Sheets("Paste").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Next rng
Worksheets("Paste").Activate
End Sub

I believe I understand the “Copy Sheets("Paste").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)” part and it works just as I need. I do not understand how “ Union(rng.Resize(, 2), rng.Resize(, 1).Offset(, 4)).” selects columns A,B and E and how to change it to get me to the results I need. Thanks


Note:
Union(rng.Resize(, 2), rng.Resize(, 1).Offset(, 4)).Copy Sheets("Paste").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
Is one line.
Attached Files
File Type: xlsm Book4A.xlsm (20.2 KB, 2 views)
Reply With Quote