Copy/Paste Section Values with Offset

ipperz

New Member
Joined
Feb 1, 2018
Messages
12
Hello,

I am looking for recommendations to speed up a macro. The below macro copies a lot of formulas located in A2:R43, pastes the selection every 47 rows, then pastes the new values of the formulas over the previous paste.


Code:
'Copy/Pastes A2:R43 the number of times equaling A1's value

    For i = 1 To Worksheets("Calc Sheet").Range("A1").Value
      Range("A2:R43").Copy Destination:=Range("A2").Offset(47 * i)
    
    
'Copy/Paste below formulas into values over itself

    Range("A2:R43").Offset(47 * i).Copy
    Range("A2").Offset(47 * i).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Selection.Cut

    Range("A2").Offset(47 * i).Select
    ActiveSheet.Paste
    Next i

Thank you!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
Code:
    For I = 1 To Worksheets("Calc Sheet").Range("A1").Value
      Range("A2:R43").Copy Destination:=Range("A2").Offset(47 * I)
      With Range("A2").Offset(47 * I)
         .Value = .Value
      End With
    Next I
 
Upvote 0
Does this do what you want?
Code:
Sub ipperz()
Application.ScreenUpdating = False
For i = 1 To Worksheets("Calc Sheet").Range("A1").Value
    Range("A2:R43").Copy
    With Range("A2:R43").Offset(47 * i)
      .PasteSpecial Paste:=xlPasteAll
      .Calculate
      .Value = .Value
    End With
Next i
With Application
    .CutCopyMode = False
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0
Thanks Fluff and JoeMo!

I may have been unclear in original post, my apologies. The pastes formulas below row 47 should be set as values only, and your suggestions seem to be keeping the formula format of the paste.
 
Upvote 0
Whilst my code was wrong it should have been
Code:
   For I = 1 To Worksheets("Calc Sheet").Range("A1").Value
      Range("A2:R43").Copy Destination:=Range("A2").Offset(47 * I)
      With Range("A2:R43").Offset(47 * I)
         .Value = .Value
      End With
    Next I
JoeMo's code converts all the formulae to values.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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