ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I copy a range of cells in Excel using variables? (https://www.excelbanter.com/excel-programming/327249-how-do-i-copy-range-cells-excel-using-variables.html)

Dominic Prince

How do I copy a range of cells in Excel using variables?
 
I need to copy a range of cells from one worksheet to another worksheet in
the same workbook, but i need to define where the range is using variables
and i can't seem to get the range selection to work...

is there a way to code using the range function and variables or is there
another way to do it?

Jim Thomlinson[_3_]

How do I copy a range of cells in Excel using variables?
 
Take a look at this code...

Sub test()
Dim rngMyRange As Range
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

i = 1
j = 1
k = 10
l = 10

Set rngMyRange = ActiveSheet.Range(Cells(i, j), Cells(k, l))

rngMyRange.Copy
End Sub

Without more info on what you want in terms of variables, it is hard to give
more info... But this should give you a start.

HTH

"Dominic Prince" wrote:

I need to copy a range of cells from one worksheet to another worksheet in
the same workbook, but i need to define where the range is using variables
and i can't seem to get the range selection to work...

is there a way to code using the range function and variables or is there
another way to do it?



All times are GMT +1. The time now is 08:30 AM.

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