LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Counting Nested If Statements

Hi. This small demo returns 3. Not sure if this covers all situations
though.

Sub Demo()
Dim s, t
Dim n As Long

'// Put formula in B1
[B1].Formula = "=IF(A1=1,10,IF(A1=2,20, IF(A1=3,30)))"

'// Then...
s = [B1].Formula
t = Replace(s, "IF(", vbNullString)
n = (Len(s) - Len(t)) / 3
Debug.Print n
End Sub

HTH
--
Dana DeLouis
Win XP & Office 2003


"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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested IF statements TwoDot Excel Worksheet Functions 4 February 8th 07 12:17 AM
Nested if statements - is there a better way? masterbaker Excel Worksheet Functions 3 July 25th 06 04:59 PM
Nested IF statements maacmaac Excel Discussion (Misc queries) 2 January 23rd 06 10:18 PM
Nested IF statements John Simons Excel Worksheet Functions 14 February 16th 05 06:17 AM
nested statements Sherri New Users to Excel 6 December 3rd 04 07:04 PM


All times are GMT +1. The time now is 11:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"