PDA

View Full Version : Copying an active range



NWE
07-02-2019, 08:48 AM
Hi,

I am attempting to copy an active range from one sheet and paste it on another. So far my code is:


Worksheets("Sheet1").Range("Activerange(A:G").Copy _
Destination:=Worksheets("Sheet2").Range("A1")


The stickler is, I only want the active range of cells A through G, not the entire sheet. Any thoughts?

p45cal
07-02-2019, 09:09 AM
What is an active range?
Is it the selected cells? Perhaps the active cell?
One of these perhaps:?
Intersect(ActiveCell.EntireRow, Range("A:G")).Copy Worksheets("Sheet2").Range("A1")
Intersect(Selection.EntireRow, Range("A:G")).Copy Worksheets("Sheet2").Range("A1")

NWE
07-02-2019, 09:23 AM
I can elaborate a bit more:


Sub Breakout()
Worksheets("Contract").Activate
Worksheets("Contract").Range("A1:G84").Copy Worksheets("LBS").Range("A1")
Worksheets("As Built").Activate
Worksheets("As Built").Range("H1:I84").Copy Worksheets("LBS").Range("H1")


This works as the last line in the active sheets is row 84, however this is manually inputted. Basically I want to say "copy A1 to last active row" to sheet "LBS" automatically.

Paul_Hossler
07-02-2019, 09:24 AM
For "ActiveRange" (which doesn't exist) I assume you wanted .UsedRange:



With Worksheets("Sheet1")
Intersect(.UsedRange, .Range("A:G")).Copy Worksheets("Sheet2").Range("A1")
End With


BTW, your code has a few extra quotes floating around

NWE
07-02-2019, 09:47 AM
That worked perfectly. Thanks sir..I'll watch those quotations.