Loop/Repeat Macro

c0087

Board Regular
Joined
Jul 13, 2015
Messages
94
Office Version
  1. 365
Platform
  1. Windows
I'm trying to automatically run this so after it finishes copying Sheet "Corp" to a new sheet, it will change the R[-2] to R[-3], then copy/paste "Corp", change to R[-4], etc etc. The final run should be R[-1465].

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'
  
    ActiveCell.FormulaR1C1 = "=ABS(CD_4[@N2]-R[-2]C[-8])"
    Range("L1468").Select
    Selection.AutoFill Destination:=Range("L2:L1468"), Type:=xlFillDefault
    Range("L2:L1468").Select
    Sheets("Corp").Select
    Cells.Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
End Sub
 
Try
VBA Code:
Sub Macro1()
Dim T&
    For T = 2 To 1465
    ActiveCell.FormulaR1C1 = "=ABS(CD_4[@N2]-R[-" & T & "]C[-8])"
    Range("L1468").Select
    Selection.AutoFill Destination:=Range("L2:L1468"), Type:=xlFillDefault
    Range("L2:L1468").Select
    Sheets("Corp").Select
    Cells.Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Next T
End Sub
It runs, and copies the sheets, however all the Sheets are identical (as if the R value never changes)
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Without seeing the file it is not possible to understand problem.
Except for formula all other code is same . Hence data copied is same to all sheets.
If possible show the expected results in a file.
File is to be uploaded to some website and link given here.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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