I have thousands of cells that refer to a dynamic named range. They slow down my workbook tremendously, because the named range is recalculated every time the sheet calculates which forces those thousands of cells to recalculate and each one of those thousands of cells forces the named range to recalculate again.
Exmple:
myRange RefersTo : "=Offset($B$12,1,0,CodesCount,1)"
$C$12 formula : "=CountIf(myRange,$B12)" copied down 10,000+ rows.
The formulas in cells $C$12:$C$10,000+ force myRange to recalculate 10,000+ times.
I thimk I have discovered a way to avoid all the calculations.
myRange RefersTo : "=myOffset($B$12,1,0,CodesCount,1)"
Function myOffset(rAnchor as Range, lRows as Long, lCols as Long, lHeight as Long, lWidth as Long) as Range
Set myOffset = rAnchor.Offset(lRows, lCols).Resize(lHeight, lWidth)
End Function
Private Sub Worksheet_Calculate()
With Me
If .Range("Calculate").Value <> .Range("CodesCount") Then
.Range("CodesCount").Value = .Range("Calculate").Value
End If
End With
End Sub
Range("Calculate") calculates what the value of CodesCount should be and automatically changes the value of CodesCount and forces myRange to recalculate which forces those thousands of cells to recalculate.
The only issue I have with this solution is this:
If I have a 2nd dynamic named range dependent on CodeCount, only 1 of them gets calculated when CodesCount changes.
my2ndRange RefersTo : "=myOffset($C$12,1,0,CodesCount,1)" - doesn't recalculate automatically
As far as I can tell it's not a problem. Any formula that is dependent on my2ndRange forces it to recalculate, and if I use my2ndRange in a macro, it also forces it to recalculate, but it's unnerving for it not to recalculate automatically.
Before I change all my RefersTos to use my UDF(), does anyone see a problem with this solution?
Also, does anyone have an idea why my2ndRange doesn't automatically recalculate?
Bookmarks