Solved

# If statement with a twist---URGENT

Posted on 2011-02-16
234 Views
Hi All!

I have a large spreadsheet with nearly a million rows.  I have a column (L)=Var% which is a percentage.  What I need to do is create a column that tells the following:

if L >=0% but <=5% then '0'
if L >=10% but <=20% then '.15'
if L >=21% but <=40% then '.30'
if L >=41% but <=60% then '.50'
if L >=61% but <=80% then '.70'
if L <0% but >=-9% then '0'
if L <-10% but >=-20% then '-.15'
if L <-21% but >=-40% then '-.30'
if L <-41% but >=-60% then '-.50'
if L <-61% but >=-80% then '-.70'
if L <-81% but >=-99% then '-.80'
else '0'

Your help would be greatly appreciated.

spudmcc
0
Question by:spudmcc
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 53

Expert Comment

ID: 34908456
put this function into Alt+F11

then use

B1 =getValue(A1)

assuming your data in in col A

copy down
``````Function getValue(L As Double) As Double

If L >= 0 And L <= 5 Then
getValue = 0
ElseIf L >= 10 And L <= 20 Then
getValue = 0.15
ElseIf L >= 21 And L <= 40 Then
getValue = 0.3
ElseIf L >= 41 And L <= 60 Then
getValue = 0.5
ElseIf L >= 61 And L <= 80 Then
getValue = 0.7
ElseIf L < 0 And L >= -9 Then
getValue = 0
ElseIf L < -10 And L >= -20 Then
getValue = -0.15
ElseIf L < -21 And L >= -40 Then
getValue = -0.3
ElseIf L < -41 And L >= -60 Then
getValue = -0.5
ElseIf L < -61 And L >= -80 Then
getValue = -0.7
ElseIf L < -81 And L >= -99 Then
getValue = -0.8
Else
getValue = 0
End If

End Function
``````
0

Author Comment

ID: 34908707
Lots of zero's and nothing else.  ??????
0

LVL 9

Accepted Solution

hitsdoshi1 earned 500 total points
ID: 34908804
There you go... I changed the code to reflect the % value.

Credit to HainKurt.
``````Function getValue(L As Double) As Double

If L >= 0 And L <= 0.05 Then
getValue = 0
ElseIf L >= 0.1 And L <= 0.2 Then
getValue = 0.15
ElseIf L >= 0.21 And L <= 0.4 Then
getValue = 0.3
ElseIf L >= 0.41 And L <= 0.6 Then
getValue = 0.5
ElseIf L >= 0.61 And L <= 0.8 Then
getValue = 0.7
ElseIf L < 0 And L >= -0.09 Then
getValue = 0
ElseIf L < -0.1 And L >= -0.2 Then
getValue = -0.15
ElseIf L < -0.21 And L >= -0.4 Then
getValue = -0.3
ElseIf L < -0.41 And L >= -0.6 Then
getValue = -0.5
ElseIf L < -0.61 And L >= -0.8 Then
getValue = -0.7
ElseIf L < -0.81 And L >= -0.99 Then
getValue = -0.8
Else
getValue = 0
End If
``````
0

LVL 53

Expert Comment

ID: 34908875
lol :) I thought you have numbers between -100 & +100
I guess you have numbers between -1 & +1
0

Author Closing Comment

ID: 34934609
This worked great!  I so appreciate all of your help, patience and talent.  Thank you so much.

spudmcc (Andy)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
###### Suggested Courses
Course of the Month6 days, 13 hours left to enroll