# How to copy lines of data FAST !

#### hhenrion

##### Board Regular
Hi experts,

I have a lot of data in one sheet (distributed on many lines, sometimes consecutive, sometimes not) covering each time 60 consecutive rows.

I need to copy them, apply a mathematical formula, and paste the value in a different sheet.

I am copying in a 2 dimensional table, processing, and pasting.
And it take ages...

What is the fastest way of passing lines of 60 rows of data in a table ?

regards,

H.

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### GlennUK

##### Well-known Member
How are you doing it at the moment? By hand? By macro?

#### hhenrion

##### Board Regular
MACRO

Hi Glenn,

one piece of information I had forgotten to mention : I use a MACRO.

Rgds,

H.

#### GlennUK

##### Well-known Member
In that case post the current macro. There may be something simple to change to improve performance.

#### hhenrion

##### Board Regular

Macro - Text

Here it is :

Sheets("Prod").Select
For i = 1 To 6
For j = 1 To 10
For k = 1 To 60
Prod((i - 1) * 10 + (j - 1) * 4 + 1, k) = Range("F17").Offset((i - 1) * 200 + (j - 1) * 7, k - 1).Value
Prod((i - 1) * 10 + (j - 1) * 4 + 2, k) = Range("F17").Offset((i - 1) * 200 + (j - 1) * 7 + 1, k - 1).Value
Prod((i - 1) * 10 + (j - 1) * 4 + 3, k) = Range("F62").Offset((i - 1) * 200 + (j - 1) * 7, k - 1).Value
Prod((i - 1) * 10 + (j - 1) * 4 + 4, k) = Range("F62").Offset((i - 1) * 200 + (j - 1) * 7 + 1, k - 1).Value
Next k
Next j
Next i
Sheets("Scen").Select
For ij = 1 To 120
For k = 1 To 60
Range("SC_TOP_PCO").Offset(ij, 2 + k).Value = Prod(ij, k)
Next k
Next ij

Rgds,

H.

#### GlennUK

##### Well-known Member
Looking at your logic, you are copying contiguous blocks ( 60 cells per row ), from one sheet to another, but are doing one cell at a time instead of a block at a time, and are storing it in an array in between. You can put the values directly in the second sheet without going through an array, and do a block at a time like this:
Code:
``````Sheets("Prod").Select
For i = 1 To 6
For j = 1 To 10
Sheets("Scen").Range("SC_TOP_PCO").Offset((i - 1) * 10 + (j - 1) * 4 + 1, 3).Resize(, 60) = Range("F17").Offset((i - 1) * 200 + (j - 1) * 7, 0).Resize(, 60).Value
Sheets("Scen").Range("SC_TOP_PCO").Offset((i - 1) * 10 + (j - 1) * 4 + 2, 3).Resize(, 60) = Range("F17").Offset((i - 1) * 200 + (j - 1) * 7 + 1, 0).Resize(, 60).Value
Sheets("Scen").Range("SC_TOP_PCO").Offset((i - 1) * 10 + (j - 1) * 4 + 3, 3).Resize(, 60) = Range("F62").Offset((i - 1) * 200 + (j - 1) * 7, 0).Resize(, 60).Value
Sheets("Scen").Range("SC_TOP_PCO").Offset((i - 1) * 10 + (j - 1) * 4 + 4, 3).Resize(, 60) = Range("F62").Offset((i - 1) * 200 + (j - 1) * 7 + 1, 0).Resize(, 60).Value
Next j
Next i``````
Let me know if it doesn't work ( done in a hurry ).

Thxs

tanks a lot,

regards,

Hervé

Replies
10
Views
271
Replies
0
Views
123
Replies
19
Views
344
Replies
3
Views
217
Replies
10
Views
157

### Forum statistics

1,144,369
Messages
5,723,950
Members
422,527
Latest member
TotalBeginner201 ### 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.

### Which adblocker are you using?    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

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