Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Case statement in variable range

Using VBA, how would I populate one cell based on the contents of another
with a Case statement?

For example, if a1 = 555 S, b1 should = "South"
a2 = 333 N, b2 should = "North"

I cannot nest an If statement in a formula, because there are more than 7
scenarios.

**Important to note that the range will vary - is there a for i to row
count statement that can be used?

Thanks in advance!

Patti


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Case statement in variable range

On Sat, 23 Aug 2003 10:22:11 -0500, "TP" wrote:

Using VBA, how would I populate one cell based on the contents of another
with a Case statement?

For example, if a1 = 555 S, b1 should = "South"
a2 = 333 N, b2 should = "North"

I cannot nest an If statement in a formula, because there are more than 7
scenarios.

**Important to note that the range will vary - is there a for i to row
count statement that can be used?

Thanks in advance!

Patti


In general, you would run a SUB and set the value property of the cell equal to
your test result. And yes you can activate the SUB to test any particular
range, or the Selection.

If you presented more information, I might be able to give a more detailed
answer. In addition, depending on your algorithm, it may be possible to devise
a formula to do what you want.

I'm not sure of the algorithm from what you've posted. But formulas using
LOOKUP, MATCH, INDEX, could possibly all do what you want. From the limited
examples you present, here are two possible solutions:


=INDEX({"North","East","South","West"},MATCH(RIGHT (A10,1),{"N","E","S","W"},0))

=CHOOSE(ROUND(MOD(LEFT(A10,3),360)/45,0)+1,"North","Northeast","East","Southeast","So uth","Southwest","West","Northwest","North")


--ron
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
Case Statement jlclyde Excel Discussion (Misc queries) 3 December 4th 08 05:04 PM
IF STATMENT OR CASE STATEMENT Richard Excel Discussion (Misc queries) 2 January 10th 07 10:04 AM
Anyone actually get Case statement to work ... ? ForestFeeder Excel Worksheet Functions 3 April 21st 06 04:14 PM
CASE statement equivalent Beema Excel Worksheet Functions 1 December 15th 04 09:32 AM
Passing a variable to a range statement Mervyn Thomas[_3_] Excel Programming 3 July 25th 03 02:40 PM


All times are GMT +1. The time now is 09:54 PM.

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

About Us

"It's about Microsoft Excel"