IF condition with multiple criteria

nikhil0311

Board Regular
Joined
May 3, 2013
Messages
200
Office Version
  1. 2013
Platform
  1. Windows

Book1
AB
1RevenueComment
2100$100 mm
375$75mm - $99mm
450$50mm - $74mm
545$15mm - $49mm
610$0mm - $14mm
Nested IF


column A has numbers and column B is the final comment i am looking to capture based on the below criteria.
For example
if the number in column A is (>= 100) greater than and equals to 100 then comment in column B should be "$100 mm"


Criteria
If >= 100 then "$100 mm"
OR
If >= 75 and <=99 then "$75mm - $99mm"
OR
If >= 50 and <=74 then "$50mm - $74mm"
OR
If >= 15 and <=49 then "$15mm - $49mm"
OR
If >0 and <=14 then "$0mm - $14mm"


let me know if you have any questions!
 
Good Day All Another Option

Code:
Public Sub AddFormat()


Dim Rng As Range
Dim F As Long
[COLOR=#d3d3d3][A1] = "Revenue": [B1] = "Comment"[/COLOR]
[COLOR=#d3d3d3]Range("A2:A6") = Application.Transpose(Array(100, 75, 50, 45, 10))[/COLOR] ' you can delete this Line
        For Each Rng In Range("B2:B6")
        With Rng
       
        TargetAddress = Rng.Offset(0, -1).Address
         
        CellConditions = Split("=AND(" & TargetAddress & ">=0," & TargetAddress & "<=14);=AND(" & TargetAddress & ">=15," & TargetAddress & "<=49);=AND(" & TargetAddress & ">=50," & TargetAddress & "<=74);=AND(" & TargetAddress & ">=75," & TargetAddress & "<=99);=" & TargetAddress & ">=100", ";")
        NumberFormat = Split("""0 mm - 14"";""15 mm - 49 mm"";""50 mm - 74 mm"";""75 mm - 99 mm"";""100 mm""", ";")
       
       Value = Cells(Rng.Row, Rng.Column - 1).Value
       .Formula = "=" & TargetAddress
        .FormatConditions.Delete
            For F = LBound(CellConditions) To UBound(CellConditions)
           
                
                .FormatConditions.Add Type:=xlExpression, Formula1:=CellConditions(F)
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                .FormatConditions(1).NumberFormat = NumberFormat(F)
                .FormatConditions(1).StopIfTrue = False
            
            Next
        End With
        Next
        
End Sub
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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