ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Copy and Paste a variable range (https://www.excelbanter.com/excel-programming/371710-how-copy-paste-variable-range.html)

IK

How to Copy and Paste a variable range
 
I have a formula returning a numerical # (like 25). I want to copy and paste
a range from Column A4 to Column GXX) Using that # number as the quantity of
rows that I have go to down.
Also the data is going to be selected from another sheet, using that
variable range specified in the sheet that the data is going to be pasted.



Gary''s Student

How to Copy and Paste a variable range
 
Let's say your formula is in cell A1, then:

Sub gsnu()
Dim howbig As Long
Dim r1 As Range
Dim r2 As Range

howbig = Range("A1").Value
Set r1 = Worksheets("Sheet2").Range(Cells(4, 1), Cells(howbig, "G"))
Set r2 = Worksheets("Sheet3").Range("A4")

r1.Copy r2
End Sub

will copy the defined block from Sheet2 to the same place in Sheet3
--
Gary''s Student


"IK" wrote:

I have a formula returning a numerical # (like 25). I want to copy and paste
a range from Column A4 to Column GXX) Using that # number as the quantity of
rows that I have go to down.
Also the data is going to be selected from another sheet, using that
variable range specified in the sheet that the data is going to be pasted.




All times are GMT +1. The time now is 04:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com