【问题标题】:find all array formulas in an excel worksheet在 Excel 工作表中查找所有数组公式
【发布时间】:2011-08-21 18:56:37
【问题描述】:

有没有办法在给定的 Excel 电子表格中查找所有数组公式?

【问题讨论】:

    标签: excel vba array-formulas


    【解决方案1】:

    看看这个例子。希望它有所帮助。

    Sub array_formula()
    Dim rRange As Range, cell As Range
    Dim tot As Integer
    Set rRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
        For Each cell In rRange
            If cell.HasArray Then
                MsgBox cell.Address & " " & cell.formula
                tot = tot + 1
             End If
         Next cell
    MsgBox "total number of array formula: " & tot
    End Sub
    

    【讨论】:

      【解决方案2】:

      对现有的(我发现它非常有用,谢谢)进行轻微升级,它将搜索所有工作表。

      Sub debug_print_array_formulas_all_sheets()
          Dim ws As Worksheet
          Dim rRange As Range, cell As Range
          Dim tot As Integer
      
          For Each ws In ThisWorkbook.Sheets
              On Error GoTo NotFound
              ws.Unprotect
              Dim v As Variant
              v = ws.UsedRange.HasFormula
              If IsNull(v) Or v Then
      
                  Set rRange = ws.UsedRange.SpecialCells(xlCellTypeFormulas)
                  tot = 0
                  For Each cell In rRange
                      If cell.HasArray Then
                          Debug.Print ws.Name & ":" & cell.Address & " " & cell.Formula
                          tot = tot + 1
                      End If
                   Next cell
                   If tot > 0 Then
                      Debug.Print "total number of array formula on " & ws.Name & ": " & tot
                      tot = 0
                   End If 
          NotFound:
              End If
          Next ws
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多