Copy data array using a variable to define the start location

ControlSystems

New Member
Joined
Aug 16, 2009
Messages
16
I need to copy data from an array of cells using a variable to define the location of the array:

example I need to copy an array 10 cells wide by 10 cells deep from a spread sheet to another but the start location may be A10 thru A100
depending on the variable locate as a value in an adjacent cell.

the current code used to do this copy always targets the data in the same cells A10:J20. I need this to be shifted by a variable to anywhere in the spread sheet colum A by changing the value located in another cell.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It's not real clear what you want to do. Can you post the current code?
 
Upvote 0
This might work: create a dynamic named range using the formula

=OFFSET(Sheet1!$A$10,Sheet1!$B$2,0,10, 10)

where Sheet1!$B$2 contains the value that the array should be offset from Sheet1!$A$10
 
Upvote 0
btadams,
the current code is as follows

Windows("Data Collection Yearly Log.xlsm").Activate
Sheets("M05229").Select
Range("A71:BJ101").Select
Application.CutCopyMode = False
Selection.Copy
Windows("PDCA Cami Primary ADC.xlsm").Activate
Sheets("M05229").Select
Range("B" & 7 + Range("A2").Value).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Currently this code works fine but the data in ("A71:BJ101") is in the same place each month, I need the data to come from the master file into the (PDCA Cami Primary ADC.xlsm") sheet which will require the ("A71:BJ101") to change cell reference each month.
I need to change the startint reference from A71 using a vaireable similar to the Paste variable lower in the code the value of A2 sets the destination location in the PDCA worksheet. I tried editing the code similar to the destination code but it failed.
 
Upvote 0
In the code below I'm assuming that before activating the master workbook "Data Collection Yearly Log.xlsm" you are in the workbook "PDCA Cami Primary ADC.xlsm" where Range("A3") contains the offset value for the master workbook:

Code:
Dim CellOffset as Long
CellOffset = Range("A3").Value

Windows("Data Collection Yearly Log.xlsm").Activate
Sheets("M05229").Select
Range("A" & 71 + CellOffset & ":BJ" & 101 + CellOffset).Select
Application.CutCopyMode = False
Selection.Copy
Windows("PDCA Cami Primary ADC.xlsm").Activate
Sheets("M05229").Select
Range("B" & 7 + Range("A2").Value).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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
Back
Top