Hello,
Can anyone assist with making the below code more efficient? It seems to be taking roughly 10-15 minutes to complete.
Thank you,
Can anyone assist with making the below code more efficient? It seems to be taking roughly 10-15 minutes to complete.
VBA Code:
Sub HierarchyFlag()
'
' HierarchyFlag Macro
'
'Disbale Excel properties while macrro runs
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
'Define Variables
Dim lRow As Long
lRow = Range("S" & Rows.Count).End(xlUp).Row
'Formula to Flag Managed Segment (Home) - NodeNumber
Range("A3:A" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C17:R304C17,Mapping!RC18))))>0,""X"","""")"
Range("B3:B" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C23:R39C23,Mapping!RC18))))>0,""X"","""")"
Range("C3:C" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C14:R99C14,Mapping!RC18))))>0,""X"","""")"
Range("D3:D" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C11:R55C11,Mapping!RC18))))>0,""X"","""")"
Range("E3:E" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C8:R53C8,Mapping!RC18))))>0,""X"","""")"
Range("F3:F" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C20:R274C20,Mapping!RC18))))>0,""X"","""")"
Range("G3:G" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C44:R6C44,Mapping!RC18))))>0,""X"","""")"
Range("H3:H" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C32:R80C32,Mapping!RC18))))>0,""X"","""")"
Range("I3:I" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C47:R8C47,Mapping!RC18))))>0,""X"","""")"
Range("J3:J" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C5:R8C5,Mapping!RC18))))>0,""X"","""")"
Range("K3:K" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C26:R213C26,Mapping!RC18))))>0,""X"","""")"
Range("L3:L" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C29:R96C29,Mapping!RC18))))>0,""X"","""")"
Range("M3:M" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C35:R283C35,Mapping!RC18))))>0,""X"","""")"
Range("N3:N" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C38:R322C38,Mapping!RC18))))>0,""X"","""")"
Range("O3:O" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C41:R3577C41,Mapping!RC18))))>0,""X"","""")"
Range("P3:P" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C50:R72C50,Mapping!RC18))))>0,""X"","""")"
Range("Q3:Q" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C53:R53C53,Mapping!RC18))))>0,""X"","""")"
'Formula to Flag Managed Segment (Impacted)-Node Number
Range("U3:U" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C17:R304C17,Mapping!RC38))))>0,""X"","""")"
Range("V3:V" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C23:R39C23,Mapping!RC38))))>0,""X"","""")"
Range("W3:W" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C14:R99C14,Mapping!RC38))))>0,""X"","""")"
Range("X3:X" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C11:R55C11,Mapping!RC38))))>0,""X"","""")"
Range("Y3:Y" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C8:R53C8,Mapping!RC38))))>0,""X"","""")"
Range("Z3:Z" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C20:R274C20,Mapping!RC38))))>0,""X"","""")"
Range("AA3:AA" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C44:R6C44,Mapping!RC38))))>0,""X"","""")"
Range("AB3:AB" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C32:R80C32,Mapping!RC38))))>0,""X"","""")"
Range("AC3:AC" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C47:R8C47,Mapping!RC38))))>0,""X"","""")"
Range("AD3:AD" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C5:R8C5,Mapping!RC38))))>0,""X"","""")"
Range("AE3:AE" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C26:R213C26,Mapping!RC38))))>0,""X"","""")"
Range("AF3:AF" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C29:R96C29,Mapping!RC38))))>0,""X"","""")"
Range("AG3:AG" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C35:R283C35,Mapping!RC38))))>0,""X"","""")"
Range("AH3:AH" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C38:R322C38,Mapping!RC38))))>0,""X"","""")"
Range("AI3:AI" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C41:R3577C41,Mapping!RC38))))>0,""X"","""")"
Range("AJ3:AJ" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C50:R72C50,Mapping!RC38))))>0,""X"","""")"
Range("AK3:AK" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT List'!R2C53:R53C53,Mapping!RC38))))>0,""X"","""")"
'Formula to Flag Accountable Executive
Range("AO3:AO" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C29:R14581C29,Mapping!RC58))))>0,""X"","""")"
Range("AP3:AP" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C41:R1048C41,Mapping!RC58))))>0,""X"","""")"
Range("AQ3:AQ" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C23:R7437C23,Mapping!RC58))))>0,""X"","""")"
Range("AR3:AR" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C11:R3791C11,Mapping!RC58))))>0,""X"","""")"
Range("AS3:AS" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C17:R2043C17,Mapping!RC58))))>0,""X"","""")"
Range("AT3:AT" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C35:R10201C35,Mapping!RC58))))>0,""X"","""")"
Range("AU3:AU" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C83:R4C83,Mapping!RC58))))>0,""X"","""")"
Range("AV3:AV" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C47:R16685C47,Mapping!RC58))))>0,""X"","""")"
Range("AW3:AW" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C89:R84C89,Mapping!RC58))))>0,""X"","""")"
Range("AX3:AX" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C5:R356C5,Mapping!RC58))))>0,""X"","""")"
Range("AY3:AY" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C95:R37613C95,Mapping!RC58))))>0,""X"","""")"
Range("AZ3:AZ" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C101:R17696C101,Mapping!RC58))))>0,""X"","""")"
Range("BA3:BA" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C53:R32501C53,Mapping!RC58))))>0,""X"","""")"
Range("BB3:BB" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C59:R35048C59,Mapping!RC58))))>0,""X"","""")"
Range("BC3:BC" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C65:R18446C65,Mapping!RC58))))>0,""X"","""")"
Range("BD3:BD" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C71:R14175C71,Mapping!RC58))))>0,""X"","""")"
Range("BE3:BE" & lRow).Formula = "=IF(SUMPRODUCT(--(ISNUMBER(SEARCH('DSMT-SOEID List'!R3C77:R155506C77,Mapping!RC58))))>0,""X"","""")"
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
'Copy Formula and Paste Special Values - Remove Formula
Range("A3:BE3" & lRow).Copy
Range("A3:P3" & lRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Thank you,