Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
TheRobsterUK
 
Posts: n/a
Default Better Way to Code IF Statements?


Is there a better way than this to code IF statements in a worksheet?


Code:
--------------------
=IF(H8=1, A1, IF(H8=2, A2, IF(H8=3, A3, A4)))
--------------------


As the code shows, the common reference cell is H8 and the IF statement
checks it's value (from a range of 1-3) and then makes the target cell
equal one out of a range of cells depending on the outcome.

This is a short example but I have some very long and complex IF
statements that use this method and was wondering if there was a way to
simplify e.g. by using array formulas or something similar?

Something along the lines of:


Code:
--------------------
=[IF(H8 = 1;2;3, A1;A2;A3, A4)]
--------------------


That obviously doesn't work but that's the kind of thing I was
thinking.

Cheers
-Rob


--
TheRobsterUK


------------------------------------------------------------------------
TheRobsterUK's Profile: http://www.excelforum.com/member.php...fo&userid=9924
View this thread: http://www.excelforum.com/showthread...hreadid=387970

  #2   Report Post  
JE McGimpsey
 
Posts: n/a
Default

One way:

Since you indicate that H8 will always be 1, 2, or 3:

=CHOOSE(H8, A1, A2, A3)

but then you throw in A4, so perhaps

=IF(AND(H8=1,H8<=3),CHOOSE(H8,A1,A2,A3),A4)

or, depending on what values H8 may take on, a Lookup formula would be
better.



In article ,
TheRobsterUK
wrote:

Is there a better way than this to code IF statements in a worksheet?


Code:
--------------------
=IF(H8=1, A1, IF(H8=2, A2, IF(H8=3, A3, A4)))
--------------------


As the code shows, the common reference cell is H8 and the IF statement
checks it's value (from a range of 1-3) and then makes the target cell
equal one out of a range of cells depending on the outcome.

This is a short example but I have some very long and complex IF
statements that use this method and was wondering if there was a way to
simplify e.g. by using array formulas or something similar?

Something along the lines of:


Code:
--------------------
=[IF(H8 = 1;2;3, A1;A2;A3, A4)]
--------------------


That obviously doesn't work but that's the kind of thing I was
thinking.

Cheers
-Rob

  #3   Report Post  
Ron Coderre
 
Posts: n/a
Default


If cell H8 will actually contain integer values of 1 or greater, you
might be able to work with one of these:

=CHOOSE(H8, A1,A2,A3,A4,A5)
whe
If H8 is 2, the formula returns A2
If H8 is 5, the formula returns A5

OR

=INDIRECT("A"&H8)

Does that help?

Ron


--
Ron Coderre
------------------------------------------------------------------------
Ron Coderre's Profile: http://www.excelforum.com/member.php...o&userid=21419
View this thread: http://www.excelforum.com/showthread...hreadid=387970

  #4   Report Post  
Morrigan
 
Posts: n/a
Default


I'd use VLOOKUP. Might be cleaner at the end.


--
Morrigan
------------------------------------------------------------------------
Morrigan's Profile: http://www.excelforum.com/member.php...fo&userid=7094
View this thread: http://www.excelforum.com/showthread...hreadid=387970

  #5   Report Post  
RagDyeR
 
Posts: n/a
Default

If your cells to be polled are in a specific, contiguous range, you could
try this:

=INDEX(A1:A4,H8)

Where there is *no* A4 "fallback" return, but an A4 specific reference.

If the A4 return is necessary, you could try something like this:

=IF(ISERR(INDEX(A1:A3,H8)),A4,INDEX(A1:A3,H8))
--

HTH,

RD
==============================================
Please keep all correspondence within the Group, so all may benefit!
==============================================



"TheRobsterUK"
wrote in message
news:TheRobsterUK.1sd9eb_1121691903.8943@excelforu m-nospam.com...

Is there a better way than this to code IF statements in a worksheet?


Code:
--------------------
=IF(H8=1, A1, IF(H8=2, A2, IF(H8=3, A3, A4)))
--------------------


As the code shows, the common reference cell is H8 and the IF statement
checks it's value (from a range of 1-3) and then makes the target cell
equal one out of a range of cells depending on the outcome.

This is a short example but I have some very long and complex IF
statements that use this method and was wondering if there was a way to
simplify e.g. by using array formulas or something similar?

Something along the lines of:


Code:
--------------------
=[IF(H8 = 1;2;3, A1;A2;A3, A4)]
--------------------


That obviously doesn't work but that's the kind of thing I was
thinking.

Cheers
-Rob


--
TheRobsterUK


------------------------------------------------------------------------
TheRobsterUK's Profile:
http://www.excelforum.com/member.php...fo&userid=9924
View this thread: http://www.excelforum.com/showthread...hreadid=387970


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
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 4th 05 10:50 AM
Opening a file with code without a set file name jenkinspat Excel Discussion (Misc queries) 1 March 3rd 05 03:40 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM


All times are GMT +1. The time now is 09:07 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"