How to count formulas in an Excel file
The 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.