PDA

View Full Version : Solved: if-else query



cruise
06-12-2012, 02:20 AM
In the "Frequency" column, I have data like this
frequency Calculation
0.02% rare
1% common
4% common
I want to print the word in below format in column "calculation' in below if-else conditon. How to do. Plz help.
very common 10%,
common 1% to < 10%;
uncommon 0.1% to < 1%;
rare 0.01% to < 0.1%;
very rare < 0.01%.

Aussiebear
06-12-2012, 02:23 AM
Use Case Select rather than If Else

cruise
06-12-2012, 02:35 AM
Is it possible for you to write the code as I am new to this.

cruise
06-12-2012, 02:53 AM
I am getting error. could you please check

sub x()
Dim score As Integer, grade As String
score = column("M:M").Value
If score = 10% Then
grade = "very common"
Else if score >= 1% and score <=10%Then
grade = "common"
End If
column("N:N").Value = grade
end sub

CodeNinja
06-12-2012, 06:12 AM
Hi Cruise,
I think you are looking for something like this.... Be sure to change the for i = 1 to ... to reflect your starting row, and change sheet1 to whatever sheet you are using... Good luck.


Sub x()
Dim score As Double
Dim grade As String
Dim i As Integer
For i = 1 To Sheet1.Range("M65536").End(xlUp).Row 'assuming you start at row 1
score = Sheet1.Cells(i, 13)
Select Case score
Case Is < 0.0001
grade = "Very Rare"
Case Is < 0.001
grade = "Rare"
Case Is < 0.01
grade = "Uncommon"
Case Is < 0.1
grade = "Common"
Case Else
grade = "Very Common"
End Select
Sheet1.Cells(i, 14) = grade
Next i
End Sub

cruise
06-12-2012, 10:47 AM
Thanks ninja for your great help