Macro to run IF Statement

ExcelNovice

Well-known Member
Joined
May 12, 2002
Messages
583
I'm trying to get a macro that will populate cell C3 with the word "Excellent" if cell B3 is > 1; "Satisfactory" if B3 is > 2.5; "Fair" if B3 is > 3.5; "Moderate" if B3 is > 4.5; "Average" if B3 is > 6 and "Poor" if B3 is > 7.

I know how to do this using IF Statement, but I would prefer to use a macro. Your help will be appreciated.

Thanks.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The following code with achieve what you have asked for. If you are trying to do this for a range of cells, you will need to loop it.

Sub Macro1()
Select Case Range("B3").Value
Case Is > 7
Range("C3").Value = "Poor"

Case 6 To 7
Range("C3").Value = "Average"

Case 4.5 To 5
Range("C3").Value = "Moderate"

Case 3.5 To 4.5
Range("C3").Value = "Fair"

Case 2.5 To 3.5
Range("C3").Value = "Satisfactory"

Case 1 To 2.5
Range("C3").Value = "Excellent"
End Select
End Sub
 
Upvote 0
Like MoseOfOz, I also chose to use Select Case rather than multiple IF statements ...

Code:
Sub yselect()
'10/06/02 -- Yogi Anand Use of Case in lieu of nested IFs
Dim Number
Dim Result As String
Number = Sheets("sheet6").Range("B3")

Select Case Number
    Case Is > 7
        Result = "poor"
    Case Is > 6
        Result = "average"
    Case Is > 4.5
        Result = "Moderate"
    Case Is > 3.5
        Result = "Fair"
    Case Is > 2.5
        Result = "Satisfactory"
    Case Is > 1
        Result = "Excellent"
Case Else
    Debug.Print "Result Not Available for <=1"
End Select
Debug.Print Result
End Sub

Regards!

Yogi
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top