16th February 2008

How to count formulas in an Excel file

Download the full solution.


Count formulas in ExcelThe code for this is below:Dim FirstSheet As IntegerPrivate Sub cmdCancel_Click()
Unload Me
Sheets(FirstSheet).Select
End
End Sub

Private Sub cmdOk_Click()
Dim Total As Double, SubTotal As Double
Dim i As Integer
Dim StartTime As Variant
StartTime = Now()
Me.MousePointer = fmMousePointerHourGlass
Total = 0

If optThis.Value = True Then
    On Error Resume Next
    Total = Selection.SpecialCells(xlCellTypeFormulas, 23).Count
End If
If optEntire.Value = True Then
    For i = 1 To ActiveWorkbook.Sheets.Count
        SubTotal = 0
        Sheets(i).Activate
        On Error Resume Next
        SubTotal = Selection.SpecialCells(xlCellTypeFormulas, 23).Count
        Total = Total + SubTotal
    Next i
End If
If optSelection.Value = True Then
    Dim SelRange As Range
    Dim address As String
    address = RefEdit1.Value
    Set SelRange = Range(address)
    On Error Resume Next
    Total = SelRange.SpecialCells(xlCellTypeFormulas, 23).Count
End If
Me.MousePointer = fmMousePointerDefault
If Total = 0 Then
    MsgBox “There were no formulas counted.” & vbCrLf & “Total time: ” & Format(Now() - StartTime, “h:m:ss”), , “Formula Count”
Else
    MsgBox “There were ” & Format(Total, “###,###,###”) & ” formulas counted.” & vbCrLf & “Total time: ” & Format(Now() - StartTime, “h:m:ss”), , “Formula Count”
End If
Sheets(FirstSheet).Select
End Sub

Private Sub optEntire_Click()
Frame2.Visible = False
End Sub

Private Sub optSelection_Click()
Frame2.Visible = True
Frame2.SetFocus
End Sub

Private Sub optThis_Click()
Frame2.Visible = False
End Sub

Private Sub UserForm_Initialize()
optThis.Value = True
FirstSheet = ActiveWorkbook.ActiveSheet.Index
End Sub


Download the full solution.

This entry was posted on Saturday, February 16th, 2008 at 8:59 pm and is filed under Microsoft Excel, Microsoft Office. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

  • Links

  • Calendar

  • February 2012
    S M T W T F S
    « Jan    
     1234
    567891011
    12131415161718
    19202122232425
    26272829