COPY PASTE WIDE RANGE OF CELLS WITH FORMULAS FROM ONE SHEET TO ANOTHER SHEET

Rob_Tob_2

New Member
Joined
May 30, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a problem trying to codifying a copy paste a wide range of cells from one sheets with many formulas that are changing because there is a loop, to another sheet.

This is in my example:

First Part
Cash Flows from 1 to 246 that create a loop to generate a projection cash flows for each contract.

The problem is to copy paste these 246 rows with formulas that changed because the loop, to another sheet for each contract in this loop.

I created the following code:

Sub PRESTACIONES()
'
' PRESTACIONES Macro
'
Dim n As Single
Dim t As Single


n = Sheets("CÁLCULO PRESTACIONES").Range("b2").Value
t = Sheets("CÁLCULO PRESTACIONES").Range("b1").Value

Application.ScreenUpdating = False

' limpio las hojas

ThisWorkbook.Sheets("TOTAL PRESTACIONES").Range("a3:o100000").ClearContents

ThisWorkbook.Sheets("CÁLCULO PRESTACIONES").Activate
ThisWorkbook.Sheets("CUADRE PRESTACIONES").Activate
ThisWorkbook.Sheets("TOTAL PRESTACIONES").Activate

For t = 1 To n

ThisWorkbook.Sheets("CÁLCULO PRESTACIONES").Select
Sheets("CÁLCULO PRESTACIONES").Range("b1").Value = t

Application.StatusBar = "Procesando Registro " & t

ThisWorkbook.Sheets("CUADRE PRESTACIONES").Activate
ThisWorkbook.Sheets("CUADRE PRESTACIONES").Range("A3:K146").Select
Selection.Copy
ThisWorkbook.Sheets("TOTAL PRESTACIONES").Activate
ThisWorkbook.Sheets("TOTAL PRESTACIONES").Select
Range("a1").Select
Selection.Offset(t + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Next

End Sub

So if you look at the last part where you can see "Range("A3:K146")", the code ends pasting the first row for each contract and the all ones for the final contract, but just the final contract (246), but not for the previous ones.

How can I solve this problem to paste the entire 246 rows for each contract and not only for last contract?

Thank you
 

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

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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