View Single Post
 
Old 05-18-2023, 04:29 AM
p45cal's Avatar
p45cal p45cal is offline Windows 10 Office 2019
Expert
 
Join Date: Apr 2014
Posts: 956
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

This should make it a bit easier to choose which columns you want copying:
Code:
Sub blah()
Dim rng As Range
For Each rng In Selection.Areas
  With rng.EntireRow
    Union(.Columns("B:C"), .Columns("E:E"), .Columns("G:G"), .Columns("J:J")).Copy Sheets("Paste").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
  End With
Next rng
Worksheets("Paste").Activate
End Sub
This doesn't quite act in the same way as your original code which took horizontal offsets from the selection; this means that if an area's first column wasn't column A, the cells copied were offset from that column, not column A. If you want it still to operate that way, change the line:
With rng.EntireRow
to:
With rng

Note that whichever you choose above, you won't need to select ranges which cover all the columns you want to copy, only the leftmost column. Moreover, if you leave EntireRow in, it doesn't matter which column(s) you choose at all.
Reply With Quote