I am not quite sure why this is occurring, but I cannot seem to identify a solution online. I am merely attempting to copy some formulas from one sheet to another (the formula will .FillDown
in the destination sheet), but I am having issues with one formula in particular. I believe it is because the formula is an array, but even when I use .Range.FormulaArray
I receive the same #REF!
error. Here is the formula and the script that transfers it:
(Note: the references in the formula are accurate for the destination sheet, not the origin sheet - the formula is maintained in a designated sheet because all of the data on the destination sheet is deleted when closing the workbook to reduce file size)
Intended Formula
IF(LEFT(H2,1)="2","Platforms",INDEX('Units - Job Numbers'!$A$2:$A$200,SMALL(IF('Units - Job Numbers'!$B$2:$CO$200=I2,ROW('Units - Job Numbers'!$B$2:$CO$200)-ROW('Units - Job Numbers'!$B$2)+1),1)))
Formula After Transfer
=IF(LEFT(H2,1)="2","Platforms",INDEX('Units - Job Numbers'!#REF!,SMALL(IF('Units - Job Numbers'!#REF!=I2,ROW('Units - Job Numbers'!#REF!)-ROW('Units - Job Numbers'!#REF!)+1),1)))
VBA
'Copy and Extend Raw WIP Data Formulas
With ThisWorkbook.Worksheets("Raw WIP Data")
.Range("AE2:AL2").Formula = ThisWorkbook.Worksheets("Formulas").Range("A7:H7").Formula
.Range("AM2").Formula = ThisWorkbook.Worksheets("Formulas").Range("I7").Formula
.Range("AE2:AM" & WIPLastRow).FillDown
.Range("AE2:AM" & WIPLastRow).Copy
.Range("AE2:AM" & WIPLastRow).PasteSpecial xlPasteValues
Application.CutCopyMode = False
ActiveSheet.Cells(1, 1).Select
End With
When the formula transfers to the destination sheet, all of the references in 'Units - Job Numbers' sheet become #REF!
. Strangely enough, the original formula has the #REF!
errors even though the formula was correct before executing the macro. Any suggestions?