Code:
It's my first post on this forum, hello everyone!!!!
I was wondering if anyone know any way to speed up below code a little. It's exhausting RAM quite often especially if more than 1 spreadsheet I'd opened.
Code:
Sub Recalculate()
'
' Recalculate Macro
'
'
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlAutomatic
'Clear content
Range("C5:AP54").ClearContents
Range("C5:AP54").ClearComments
'C5 - Reactive Actions
Range("C5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C[-2]:C[8],SMALL(IF(Sheet1!C[11]=""Reactive"",IF((Area=Sheet1!C[-2]),IF((Sheet1!C[53]=""Open Actions""),ROW(Sheet1!C[-2])-MIN(ROW(Sheet1!C[-2]))+1,"""")),""""),ROW(R[-4]C[3])),11),"""")"
Selection.AutoFill Destination:=Range("C5:C54"), Type:=xlFillDefault
Range("C5:C54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'D5
Range("D5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[2], MATCH(RC[-1],Sheet1!C[7],0)),"""")"
Selection.AutoFill Destination:=Range("D5:D54"), Type:=xlFillDefault
Range("D5:D54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'E6
Range("E5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[4], MATCH(RC[-2],Sheet1!C[6],0)),"""")"
Selection.AutoFill Destination:=Range("E5:E54"), Type:=xlFillDefault
Range("E5:E54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'F6
Range("F5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[60], MATCH(RC[-3],Sheet1!C[5],0)),"""")"
Selection.AutoFill Destination:=Range("F5:F54"), Type:=xlFillDefault
Range("F5:F54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'G5
Range("G5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("G5:G54"), Type:=xlFillDefault
Application.CutCopyMode = False
'H5 - Planned Actions
Range("H5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C11,SMALL(IF(Sheet1!C14=""Extra Works"",IF((Area=Sheet1!C1),IF((Sheet1!C56=""Open Actions""),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,"""")),""""),ROW(R[-4]C[-1])),11),"""")"
Selection.AutoFill Destination:=Range("H5:H54"), Type:=xlFillDefault
Range("H5:H54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'I5
Range("I5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-3], MATCH(RC[-1],Sheet1!C[2],0)),"""")"
Selection.AutoFill Destination:=Range("I5:I54"), Type:=xlFillDefault
Range("I5:I54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'J5
Range("J5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-1], MATCH(RC[-2],Sheet1!C[1],0)),"""")"
Selection.AutoFill Destination:=Range("J5:J54"), Type:=xlFillDefault
Range("J5:J54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'K5
Range("K5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[55], MATCH(RC[-3],Sheet1!C,0)),"""")"
Selection.AutoFill Destination:=Range("K5:K54"), Type:=xlFillDefault
Range("K5:K54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'L5
Range("L5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("L5:L54"), Type:=xlFillDefault
'M5 - Extra Works Actions
Range("M5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C11,SMALL(IF(Sheet1!C14=""Planned"",IF((Area=Sheet1!C1),IF((Sheet1!C56=""Open Actions""),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,"""")),""""),ROW(R[-4]C[-6])),11),"""")"
Selection.AutoFill Destination:=Range("M5:M54"), Type:=xlFillDefault
Range("M5:M54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'N5
Range("N5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-8], MATCH(RC[-1],Sheet1!C[-3],0)),"""")"
Selection.AutoFill Destination:=Range("N5:N54"), Type:=xlFillDefault
Range("N5:N54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'O5
Range("O5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-6], MATCH(RC[-2],Sheet1!C[-4],0)),"""")"
Selection.AutoFill Destination:=Range("O5:O54"), Type:=xlFillDefault
Range("O5:O54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'P5
Range("P5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[50], MATCH(RC[-3],Sheet1!C[-5],0)),"""")"
Selection.AutoFill Destination:=Range("P5:P53"), Type:=xlFillDefault
Range("P5:P54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Q5
Range("Q5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("Q5:Q54"), Type:=xlFillDefault
Application.CutCopyMode = False
'R5 - Ambers
Range("R5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C60,SMALL(IF(Sheet1!C60=""Amber"",IF((Area=Sheet1!C1),IF(NOT(Sheet1!C[-4]=""Planned""),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,"""")),""""),ROW(R[-4]C[-11])),11),"""")"
Selection.AutoFill Destination:=Range("R5:R54"), Type:=xlFillDefault
Range("R5:R54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'S5
Range("S5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-13], MATCH(RC[-1],Sheet1!C[-8],0)),"""")"
Selection.AutoFill Destination:=Range("S5:S54"), Type:=xlFillDefault
Range("S5:S54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'T5
Range("T5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-11], MATCH(RC[-2],Sheet1!C[-9],0)),"""")"
Selection.AutoFill Destination:=Range("T5:T54"), Type:=xlFillDefault
Range("T5:T54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'U5
Range("U5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[13], MATCH(RC[-3],Sheet1!C[-10],0)),"""")"
Selection.AutoFill Destination:=Range("U5:U54"), Type:=xlFillDefault
Range("U5:U54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'V5
Range("V5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("V5:V54"), Type:=xlFillDefault
Application.CutCopyMode = False
'W5 - 3 Day Ambers
Range("W5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C60,SMALL(IF(Sheet1!C60=""3 Day Ambers"",IF((Area=Sheet1!C1),IF(NOT(Sheet1!C[-9]=""Planned""),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,"""")),""""),ROW(R[-4]C[-16])),11),"""")"
Selection.AutoFill Destination:=Range("W5:W54"), Type:=xlFillDefault
Range("W5:W54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'X5
Range("X5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-18], MATCH(RC[-1],Sheet1!C[-13],0)),"""")"
Selection.AutoFill Destination:=Range("X5:X54"), Type:=xlFillDefault
Range("X5:X54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Y5
Range("Y5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-16], MATCH(RC[-2],Sheet1!C[-14],0)),"""")"
Selection.AutoFill Destination:=Range("Y5:Y54"), Type:=xlFillDefault
Range("Y5:Y54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'Z5
Range("Z5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[8], MATCH(RC[-3],Sheet1!C[-15],0)),"""")"
Selection.AutoFill Destination:=Range("Z5:Z54"), Type:=xlFillDefault
Range("Z5:Z54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AA5
Range("AA5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("AA5:AA54"), Type:=xlFillDefault
Application.CutCopyMode = False
'AB5 - Red
Range("AB5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C60,SMALL(IF(Sheet1!C60=""Red"",IF((Area=Sheet1!C1),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,""""),""""),ROW(R[-4]C[-21])),11),"""")"
Selection.AutoFill Destination:=Range("AB5:AB54"), Type:=xlFillDefault
Range("AB5:AB54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'AC5
Range("AC5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-23], MATCH(RC[-1],Sheet1!C[-18],0)),"""")"
Selection.AutoFill Destination:=Range("AC5:AC54"), Type:=xlFillDefault
Range("AC5:AC54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AD5
Range("AD5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-21], MATCH(RC[-2],Sheet1!C[-19],0)),"""")"
Selection.AutoFill Destination:=Range("AD5:AD54"), Type:=xlFillDefault
Range("AD5:AD54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AE5
Range("AE5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[3], MATCH(RC[-3],Sheet1!C[-20],0)),"""")"
Selection.AutoFill Destination:=Range("AE5:AE54"), Type:=xlFillDefault
Range("AE5:AE54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AF5
Range("AF5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("AF5:AF54"), Type:=xlFillDefault
Application.CutCopyMode = False
'AK5 - Freebar
Range("AK5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C1:C60,SMALL(IF(Sheet1!C33=""FREE"",IF((Area=Sheet1!C1),ROW(Sheet1!C1)-MIN(ROW(Sheet1!C1))+1,""""),""""),ROW(R[-4]C[-30])),11),"""")"
Selection.AutoFill Destination:=Range("AK5:AK54"), Type:=xlFillDefault
Range("AK5:AK54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'AL5
Range("AL5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-32], MATCH(RC[-1],Sheet1!C[-27],0)),"""")"
Selection.AutoFill Destination:=Range("AL5:AL54"), Type:=xlFillDefault
Application.CutCopyMode = False
'AM5
Range("AM5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-30], MATCH(RC[-2],Sheet1!C[-28],0)),"""")"
Selection.AutoFill Destination:=Range("AM5:AM54"), Type:=xlFillDefault
Application.CutCopyMode = False
'AO5
Range("AO5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("AO5:AO54"), Type:=xlFillDefault
Application.CutCopyMode = False
'AP5 - STAT PPM
Range("AP5").Select
Selection.FormulaArray = _
"=IFERROR(INDEX(Sheet1!C[-41]:C[-31],SMALL(IF(Sheet1!C[-41]=Area,IF(Sheet1!C[-28]=""Planned"",IF((Sheet1!C[-27]=""Statutory""),IF((Sheet1!C[10]<Next),IF((Sheet1!C[10]>Last),ROW(Sheet1!C[-41])-MIN(ROW(Sheet1!C[-41]))+1,"""")))),""""),ROW(R[-4]C[-35])),11),"""")"
Selection.AutoFill Destination:=Range("AP5:AP54"), Type:=xlFillDefault
Range("AP5:AP54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Selection
Selection.NumberFormat = "General"
.Value = .Value
End With
Application.CutCopyMode = False
'AQ5
Range("AQ5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-37], MATCH(RC[-1],Sheet1!C[-32],0)),"""")"
Selection.AutoFill Destination:=Range("AQ5:AQ54"), Type:=xlFillDefault
Range("AQ5:AQ54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AR5
Range("AR5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-35], MATCH(RC[-2],Sheet1!C[-33],0)),"""")"
Selection.AutoFill Destination:=Range("AR5:AR54"), Type:=xlFillDefault
Range("AR5:AR54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AS5
Range("AS5").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(INDEX(Sheet1!C[-11], MATCH(RC[-3],Sheet1!C[-34],0)),"""")"
Selection.AutoFill Destination:=Range("AS5:AS54"), Type:=xlFillDefault
Range("AS5:AS54").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'AT5
Range("AT5").Select
ActiveCell.FormulaR1C1 = " "
Selection.AutoFill Destination:=Range("AT5:AT54"), Type:=xlFillDefault
Application.CutCopyMode = False
'borders
Range("C5:F54, H5:K54, M5:P54, R5:U54, W5:Z54, AB5:AE54, AG5:AI54, AK5:AN54, AP5:AS54").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'end
Rows("5:54").Select
Selection.RowHeight = 12
Range("F5").Select
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.CutCopyMode = False
MsgBox "All ok."
End Sub