Consulting

Results 1 to 6 of 6

Thread: Solved: if-else query

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    22
    Location

    Solved: if-else query

    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%.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Use Case Select rather than If Else
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular
    Joined
    Apr 2012
    Posts
    22
    Location
    Is it possible for you to write the code as I am new to this.

  4. #4
    VBAX Regular
    Joined
    Apr 2012
    Posts
    22
    Location
    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

  5. #5
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    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.

    [VBA]
    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
    [/VBA]

  6. #6
    VBAX Regular
    Joined
    Apr 2012
    Posts
    22
    Location
    Thanks ninja for your great help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •