简体   繁体   中英

excel bulk update all array formulas in the worksheet

In my worksheet, I have some hundreds of UNIQUE formulas (simple and array). Some of the cells contain array formulas and some simple ones. I had to bulk edit (find&replace) some characters in all formulas. I exported them as text to notepad++ and did the replacement job and brought them back and pasted back on the worksheet. When I press 'calculate the sheet' or alt + ctrl +f9, it doesn't update the array formulas. Is there any way to update (refresh) all of the formulas? or should I go one by one and press ctrl+shift+enter? which is not feasible at all given the number of cells that I have. How can I do it with a vba? thanks

You would need a routine like this - it may take a while to recalculate at the end by the sound of it!

Sub AddErrorHandler()
    Dim rngFormulas           As Range
    Dim rngCell               As Range
    Dim lngCalcMode           As Long

    On Error Resume Next
    Set rngFormulas = ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0

    If Not rngFormulas Is Nothing Then
        With Application
            .ScreenUpdating = False
            lngCalcMode = .Calculation
            .Calculation = xlCalculationManual
        End With
        For Each rngCell In rngFormulas.Cells
            If LCase$(Left$(rngCell.Formula, 9)) <> "=iferror(" Then
                If rngCell.HasArray Then
                    With rngCell.CurrentArray
                        .FormulaArray = "=IFERROR(" & Mid$(.FormulaArray, 2) & ",0)"
                    End With
                Else
                    With rngCell
                        .Formula = "=IFERROR(" & Mid$(.Formula, 2) & ",0)"
                    End With
                End If
            End If
        Next rngCell
        With Application
            .Calculation = lngCalcMode
            .ScreenUpdating = True
        End With

    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM