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.
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

btadams

Well-known Member
Joined
Jan 6, 2003
Messages
1,936
It's not real clear what you want to do. Can you post the current code?
 

btadams

Well-known Member
Joined
Jan 6, 2003
Messages
1,936
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
 

ControlSystems

New Member
Joined
Aug 16, 2009
Messages
16
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.
 

btadams

Well-known Member
Joined
Jan 6, 2003
Messages
1,936

ADVERTISEMENT

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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,569
Messages
5,512,100
Members
408,880
Latest member
FrankHH

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top