Solved

If statement with a twist---URGENT

Posted on 2011-02-16
5
237 Views
Last Modified: 2012-05-11
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
Comment
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
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Huseyin KAHRAMAN
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

Open in new window

0
 

Author Comment

by:spudmcc
ID: 34908707
Lots of zero's and nothing else.  ??????
0
 
LVL 9

Accepted Solution

by:
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

Open in new window

0
 
LVL 55

Expert Comment

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

Author Closing Comment

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

spudmcc (Andy)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
This collection of functions covers all the normal rounding methods of just about any numeric value.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
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…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question