Seeking method to copy non-contiguous columns with LastRow range method

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
719
As the title says, I am seeking to copy a non-contiguous range of cells in columns that are identified by code using Lr (LastRow).

The following works, because only the range of B6:C37 and H6:H37 are copied.

Code:
Sub CopyNonContRange()

    
    Range("B6:C37,H6:H37").Copy

End Sub

When using Lr, this does not work... Instead, the range of B6:H37 is copied.

The last row of data in all columns is the same and their are no blank cells.

Code:
Sub CopyNonContRange2()

Dim Lr As Long
Lr = Range("B" & Rows.Count).End(xlUp).Row

    
    Range("B6:C" & Lr, "H6:H" & Lr).Copy

End Sub

How can I use both Lr and copy non-contiguous ranges?

I searched, but did not come up with anything quite like what I need.

Appreciate any thoughts.

Thanks in advance.

jim
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,051
Try
Code:
Dim Lr As Long
Lr = Range("B" & Rows.Count).End(xlUp).Row

With Range("6:" & Lr)
    Application.Intersect(Range("A:C, H:H").EntireColumn, .EntireRow).Copy
End With
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,653
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Maybe... (untested)

Code:
Range("B6:C" & Lr & ",H6:H" & Lr).Copy

M.
 

Forum statistics

Threads
1,136,256
Messages
5,674,659
Members
419,521
Latest member
Jennifer4Dillon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top