Excel If Then, create a new column
Solved/Closed
AprilZ
-
Apr 8, 2011 at 11:37 AM
RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 - Apr 14, 2011 at 01:17 AM
RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 - Apr 14, 2011 at 01:17 AM
Related:
- Excel If Then, create a new column
- Create skype account with gmail - Guide
- Create new instagram account without phone number - Guide
- Create snapchat account - Guide
- Create hotmail account - Guide
- Excel mod apk for pc - Download - Spreadsheets
7 responses
RWomanizer
Posts
365
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
120
Apr 11, 2011 at 03:40 AM
Apr 11, 2011 at 03:40 AM
Use function Select Case as
Select Case pVal Case 0-10% Live Hard Coral, Low Coverage CalcValue = 1 Case 0-10% Live Hard Coral, Medium Coverage CalcValue = 2 Case 0-10% Live Hard Coral, High Coverage CalcValue = 3 Case 10-50% Live Hard Coral, Low Coverage CalcValue = 4 Case 10-50% Live Hard Coral, Medium Coverage CalcValue = 5 Case 10-50% Live Hard Coral, High Coverage CalcValue = 6 Case 50-75% Live Hard Coral, Low Coverage CalcValue = 7 Case 50-75% Live Hard Coral, Medium Coverage CalcValue = 8 Case 50-75% Live Hard Coral, High Coverage CalcValue = 9 Case >75% Live Hard Coral, Low Coverage CalcValue = 10 Case >75% Live Hard Coral, Medium Coverage CalcValue = 11 Case >75% Live Hard Coral, High Coverage CalcValue = 12 Case Else CalcValue = 0 End Select
Almost there, closer than before. At least now I can close VBA and there is a Macro present that I can select and use, that is error free.
Now, I'm not sure how to select the range for what I want this to evaluate. When I do select a column with Live/Coverage Coral data it gives me "Run-time error '28': Out of stack space"
What I would ideally like to happen would be for me to analyze the column with Live/Coverage Coral data and then the values I want assigned for each class be put into the column next to it. But, If I just have to copy the data into the next column and then run it so that the words change to my numeric values, that would be fine.
Now, I'm not sure how to select the range for what I want this to evaluate. When I do select a column with Live/Coverage Coral data it gives me "Run-time error '28': Out of stack space"
What I would ideally like to happen would be for me to analyze the column with Live/Coverage Coral data and then the values I want assigned for each class be put into the column next to it. But, If I just have to copy the data into the next column and then run it so that the words change to my numeric values, that would be fine.
RWomanizer
Posts
365
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
120
Apr 12, 2011 at 12:11 AM
Apr 12, 2011 at 12:11 AM
Can you specify what is the Range of The your data.
can you put some sample of data here
can you put some sample of data here
I have a column of data ~ 250 records long. It is called habitat. Values in this column are like those above
0-10% Live Hard Coral, Low Coverage
0-10% Live Hard Coral, Low Coverage
10-50% Live Hard Coral, High Coverage
10-50% Live Hard Coral, High Coverage
0-10% Live Hard Coral, High Coverage
.
.
.
These values are created from Concatenate function.
I would like to assign each Habitat Type (like those listed above) a value, 1-12.
I was having some luck with functions, but if I add more than one If/Then statement it will not run. Also, if I try to copy the function down the row, it returns #NAME?. I like the idea of using a function, because in the column next to my habitat column I would write CalcValue(I2), or WhateverFunction(Habitat column), and it returns my value.
0-10% Live Hard Coral, Low Coverage
0-10% Live Hard Coral, Low Coverage
10-50% Live Hard Coral, High Coverage
10-50% Live Hard Coral, High Coverage
0-10% Live Hard Coral, High Coverage
.
.
.
These values are created from Concatenate function.
I would like to assign each Habitat Type (like those listed above) a value, 1-12.
I was having some luck with functions, but if I add more than one If/Then statement it will not run. Also, if I try to copy the function down the row, it returns #NAME?. I like the idea of using a function, because in the column next to my habitat column I would write CalcValue(I2), or WhateverFunction(Habitat column), and it returns my value.
Didn't find the answer you are looking for?
Ask a question
RWomanizer
Posts
365
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
120
Apr 13, 2011 at 12:28 AM
Apr 13, 2011 at 12:28 AM
Copy and Paste this user defined funciton in Module of your code :
now write the formula in the next cell (J2) of I2 as:
=CalculateValue (I2)
you will get the required result.
Regards,
Rahul
Public function CalculateValue (rngCell As Range) As double Dim pVal as String Dim CalcValue as Double PVal = rngCell.Value Select Case pVal Case 0-10% Live Hard Coral, Low Coverage CalcValue = 1 Case 0-10% Live Hard Coral, Medium Coverage CalcValue = 2 Case 0-10% Live Hard Coral, High Coverage CalcValue = 3 Case 10-50% Live Hard Coral, Low Coverage CalcValue = 4 Case 10-50% Live Hard Coral, Medium Coverage CalcValue = 5 Case 10-50% Live Hard Coral, High Coverage CalcValue = 6 Case 50-75% Live Hard Coral, Low Coverage CalcValue = 7 Case 50-75% Live Hard Coral, Medium Coverage CalcValue = 8 Case 50-75% Live Hard Coral, High Coverage CalcValue = 9 Case >75% Live Hard Coral, Low Coverage CalcValue = 10 Case >75% Live Hard Coral, Medium Coverage CalcValue = 11 Case >75% Live Hard Coral, High Coverage CalcValue = 12 Case Else CalcValue = 0 End Select CalculateValue = CalcValue End Function
now write the formula in the next cell (J2) of I2 as:
=CalculateValue (I2)
you will get the required result.
Regards,
Rahul
Thank you very much! That did it perfectly without any errors. I've never worked with functions, and I kept getting errors, very frustrating.
Thanks again,
AZ
Thanks again,
AZ
RWomanizer
Posts
365
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
120
Apr 14, 2011 at 01:17 AM
Apr 14, 2011 at 01:17 AM
You are Most Welcome!