Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default changing nested if statements into a user defined function

I have several financial worksheets where I am figuring a percent change
with a nested if(and statements.

c1 =if(and(a1=0,b1<0),-1,if(and(a1=0,b10),1,....etc.

how do I make this into a user defined function?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default changing nested if statements into a user defined function

Hi
depends on your conditions. But in most case no UDF required but simply
applying a different alorithm or using a lookup table should work. So
you may post your complete conditions :-)

--
Regards
Frank Kabel
Frankfurt, Germany

"Rob Slagle" schrieb im Newsbeitrag
...
I have several financial worksheets where I am figuring a percent

change
with a nested if(and statements.

c1 =if(and(a1=0,b1<0),-1,if(and(a1=0,b10),1,....etc.

how do I make this into a user defined function?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default changing nested if statements into a user defined function

here is the formula that I want to make into a function in VBA

=IF(AND(I2=0,E20),1,IF(AND(I2<0,E2=0),1,IF(AND(I2 <0,E20),(K2/I2)*-1,IF(AND(I2=0,E2=0),0,IF(AND(I2=0,E2<0),-1,IF(AND(I2<0,E2<0),(K2/I2)*-1,K2/I2))))))

I2 is the prior year number.
E2 is the current year number.
K2 is the change amount E2-I2.



"Frank Kabel" wrote in message ...
Hi
depends on your conditions. But in most case no UDF required but simply
applying a different alorithm or using a lookup table should work. So
you may post your complete conditions :-)

--
Regards
Frank Kabel
Frankfurt, Germany

"Rob Slagle" schrieb im Newsbeitrag
...
I have several financial worksheets where I am figuring a percent

change
with a nested if(and statements.

c1 =if(and(a1=0,b1<0),-1,if(and(a1=0,b10),1,....etc.

how do I make this into a user defined function?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default changing nested if statements into a user defined function

Place this in a general module.

Public Function CalcVal(rng1 As Range, rng2 As Range, rng3 As Range)
Dim I2, E2, K2
I2 = rng1.Value
E2 = rng2.Value
K2 = rng3.Value

Select Case True
Case (I2 = 0 And E2 0)
CalcVal = 1
Case (I2 < 0 And E2 = 0)
CalcVal = 1
Case (I2 < 0 And E2 0)
CalcVal = (K2 / I2) * -1
Case (I2 = 0 And E2 = 0)
CalcVal = 0
Case (I2 = 0 And E2 < 0)
CalcVal = -1
Case (I2 < 0 And E2 < 0)
CalcVal = (K2 / I2) * -1
Case Else
CalcVal = K2 / I2
End Select
End Function

--
Regards,
Tom Ogilvy


"Rob Slagle" wrote in message
m...
here is the formula that I want to make into a function in VBA


=IF(AND(I2=0,E20),1,IF(AND(I2<0,E2=0),1,IF(AND(I2 <0,E20),(K2/I2)*-1,IF(AND
(I2=0,E2=0),0,IF(AND(I2=0,E2<0),-1,IF(AND(I2<0,E2<0),(K2/I2)*-1,K2/I2))))))

I2 is the prior year number.
E2 is the current year number.
K2 is the change amount E2-I2.



"Frank Kabel" wrote in message

...
Hi
depends on your conditions. But in most case no UDF required but simply
applying a different alorithm or using a lookup table should work. So
you may post your complete conditions :-)

--
Regards
Frank Kabel
Frankfurt, Germany

"Rob Slagle" schrieb im Newsbeitrag
...
I have several financial worksheets where I am figuring a percent

change
with a nested if(and statements.

c1 =if(and(a1=0,b1<0),-1,if(and(a1=0,b10),1,....etc.

how do I make this into a user defined function?




Reply
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
user defined function Pete_T Excel Worksheet Functions 1 December 1st 07 01:03 AM
Creating my own user defined function help statements Craig Excel Worksheet Functions 2 February 22nd 06 04:51 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Nested IF Statements - Worksheet Function Shorty[_2_] Excel Programming 2 April 6th 04 04:37 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 11:19 AM.

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"