Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Jackie
 
Posts: n/a
Default if then statement in VB

I have a cell say A2 that has a number in it .... I would like to return a
number value in another cell. I can write an if then else statement: if(a2 =
5 then,1,if(a2=10,2,if(a2=15,3))) etc. but this gets long (i have 30-40
parameters) I know there has to be a way to write it in VB so that I could
just go down a list (if I need to change the value later) but for some reason
I am having a problem with the language. I would appreciate any help!
--
Jackie
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default if then statement in VB

Is your example true to life, or just an example? If it's true to
life, then instead of code you might use just a formula in the other
cell:
=A2/5

Or, you might insert a new tab that holds lookup values, and on the
original sheet use VLOOKUP formulas to return a value corresponding to
the value in A2. Might these ideas work for you?

  #3   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey
 
Posts: n/a
Default if then statement in VB

No need to use VB.

One way, based on your example:

=IF(MOD(A2,5)=0,INT(A2/5),"")

but to be more flexible, use a VLOOKUP:

In another part of your workbook, perhaps a second sheet enter your
equivalents:

A B
1 5 1
2 10 2
3 15 3
....

then in your main sheet enter

=VLOOKUP(A2, Sheet2!A:B, 2, FALSE)

the fourth parameter can be true if you want an approximate match.


In article ,
Jackie wrote:

I have a cell say A2 that has a number in it .... I would like to return a
number value in another cell. I can write an if then else statement: if(a2 =
5 then,1,if(a2=10,2,if(a2=15,3))) etc. but this gets long (i have 30-40
parameters) I know there has to be a way to write it in VB so that I could
just go down a list (if I need to change the value later) but for some reason
I am having a problem with the language. I would appreciate any help!

  #4   Report Post  
Posted to microsoft.public.excel.misc
Peter Jausovec
 
Posts: n/a
Default if then statement in VB

Hi Jackie,

You can use Select Case statement:

Select Case Range("A2")
Case 5
Range("A3").Value = 1
Case 10
Range("A3").Value = 2
Case 15
Range("A3").Value = 3
....
End Select

--
Best regards,
Peter JauĆĄovec
http://blog.jausovec.net
http://office.jausovec.net


"Jackie" je napisal:

I have a cell say A2 that has a number in it .... I would like to return a
number value in another cell. I can write an if then else statement: if(a2 =
5 then,1,if(a2=10,2,if(a2=15,3))) etc. but this gets long (i have 30-40
parameters) I know there has to be a way to write it in VB so that I could
just go down a list (if I need to change the value later) but for some reason
I am having a problem with the language. I would appreciate any help!
--
Jackie

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
IF Statement problem trixma New Users to Excel 3 September 27th 05 06:36 AM
If statement Matt Montagliano Excel Discussion (Misc queries) 1 September 8th 05 08:47 PM
Do I need a sumif or sum of a vlookup formula? PeterB Excel Worksheet Functions 0 June 1st 05 12:23 PM
IF Statement Brent New Users to Excel 3 April 29th 05 04:24 PM
7+ nested if statement? Turi Excel Worksheet Functions 3 December 20th 04 07:55 PM


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