View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Counting Nested If Statements

ExcelMonkey,
How about:

Public Function CountFunction(TargetCell As Range, FunctionName As String)
As Long
Dim Temp As Variant
Temp = Split(UCase(TargetCell.Formula), UCase(FunctionName) & "(")
CountFunction = UBound(Temp)
If CountFunction < 1 Then CountFunction = 0
End Function

Unless you have other instance(s) of "if(" in the formula.

NickHK

"ExcelMonkey" wrote in message
...
Can anyone tell me how to count nested if statements in a formula via VBA.
That is I want to be able to go into a cell and assess that the formula

below
has three IF stmts

=IF(XXXXXXX,IF(XXXXXXX, IF(XXXXXX)))

This may be a Regular Expression question.

Thanks