Returning a value in a cell under specific conditions

chadski778

Active Member
Joined
Mar 14, 2010
Messages
297
I have a selection of data in four columns (F-I). I would like to return a value in column J (text - "SDS sec 3") if the value in column H contains an "R" AND the value in column F is >=1 or if the value in column H contains "43" AND the value in column F >=0.1. I would also like to format the entire row (4 columns) if the conditions are met. See example below.

Excel Workbook
ABCD
2BEFORE
3
4
5Actual%Generic NameEC HazardCAS Number
674.92Highly refined mineral oil (IP346N/CVarious
774.92Highly refined mineral oil (IP346N/C64742-62-7
874.92Highly refined mineral oil (IP346N/C64742-65-0
910Highly refined mineral oil (IP346N/C64742-54-7 or 92062-09-4
105.852Highly refined mineral oil (IP346N/C64742-65-0
113.99Polyolefin polyamine succinimide polyolR53Polymer
121.064Calcium alkaryl sulphonateR53Not available
131.064Zinc dialkyldithiophosphateR41-51/5368649-42-3
141.06Olefin co-polymerN/CConfidential
150.99Highly refined mineral oil (IP346N/CNot available
160.99PolyalkylmethacrylateN/CNot available
170.931Calcium alkaryl sulphonateR43-53Not available
180.399Borated polyolefin polyamine succinimideR53Not available
190.133Polyolefin polyamine succinimide molybdenum cmplxN/CPolymer
200.0532PolyalkarylamineR51/5368411-46-1
210.0266Branched alkanesR38-65-51/53Polymer
220.01Alkyl methacrylate (as impurity)R36/37/38-50/53142-90-5
Declarations


Excel Workbook
ABCDE
25AFTER
26
27Actual%Generic NameEC HazardCAS Number
2874.92Highly refined mineral oil (IP346N/CVarious
2974.92Highly refined mineral oil (IP346N/C64742-62-7
3074.92Highly refined mineral oil (IP346N/C64742-65-0
3110Highly refined mineral oil (IP346N/C64742-54-7 or 92062-09-4
325.852Highly refined mineral oil (IP346N/C64742-65-0
333.99Polyolefin polyamine succinimide polyolR53PolymerSDS sec 3
341.064Calcium alkaryl sulphonateR53Not availableSDS sec 3
351.064Zinc dialkyldithiophosphateR41-51/5368649-42-3SDS sec 3
361.06Olefin co-polymerN/CConfidential
370.99Highly refined mineral oil (IP346N/CNot available
380.99PolyalkylmethacrylateN/CNot available
390.931Calcium alkaryl sulphonateR43-53Not availableSDS sec 3
400.399Borated polyolefin polyamine succinimideR53Not available
410.133Polyolefin polyamine succinimide molybdenum cmplxN/CPolymer
420.0532PolyalkarylamineR51/5368411-46-1
430.0266Branched alkanesR38-65-51/53Polymer
440.01Alkyl methacrylate (as impurity)R36/37/38-50/53142-90-5
Declarations


Thanks

Chad
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Rassten, when I have "Various" in the EC Hazard column it is being selected by the macro, probably because of the "r" in the word. Any chance of making the word "various" not be selected?

Thanks
 
Upvote 0
Try this

Code:
Sub b_3_test()
fr = Cells(Rows.Count, 6).End(xlUp).Row

For x = fr To 1 Step -1
    If Range("f" & x) = "Actual%" Then y = x + 1
Next x
    

For i = fr To y Step -1

    On Error Resume Next
    a = Application.WorksheetFunction.Search("r", Range("h" & i))
    If Range("h" & i) = "Various" Then a = 0
    b = Application.WorksheetFunction.Search("43", Range("h" & i))
    On Error GoTo 0
    If (a > 0 And Range("f" & i) > 1) Or (b > 0 And Range("f" & i) > 0.1) Then
        Range("f" & i).Resize(1, 5).Interior.ColorIndex = 36
        Range("J" & i) = "SDS sec 3"
    End If
    a = 0
    b = 0
Next i

End Sub
 
Upvote 0
Sten, could you add to this macro so that it highlights rows for the following extra conditions
If any cells in range B1:B60 has an interior colour of 255 AND the value in column F is >0.1 and there is a "26" or "27" or "28" or "29" or "50/53" or "51/53" in column H in the same row
 
Upvote 0
Maybe something like:
Code:
Sub a_test()
For i = 1 To 60 Step 1
    If Range("b" & i).Interior.Color = 255 Then
        If Range("f" & i) > 0.1 Then
            If Range("h" & i) = 26 Or Range("h" & i) = 27 _
            Or Range("h" & i) = 28 Or Range("h" & i) = 29 _
            Or Range("h" & i) = "50/53" Or Range("h" & i) = "51/53" Then
                Range(i & ":" & i).EntireRow.Interior.Color = RGB(255, 255, 0)
            End If
        End If
    End If
Next i
End Sub
 
Upvote 0
How would i combine the two pieces of code you provided me to include all IF statements?

CODE 1

fr = Cells(Rows.Count, 6).End(xlUp).Row
For x = fr To 1 Step -1
If Range("f" & x) = "Actual%" Then y = x + 1
Next x

For i = fr To y Step -1
On Error Resume Next
a = Application.WorksheetFunction.Search("r", Range("h" & i))
If Range("h" & i) = "Various" Then a = 0
b = Application.WorksheetFunction.Search("43", Range("h" & i))
On Error GoTo 0
If (a > 0 And Range("f" & i) > 1) Or (b > 0 And Range("f" & i) > 0.1) Then
Range("f" & i).Resize(1, 5).Interior.ColorIndex = 36
Range("J" & i) = "SDS sec 3"
End If
a = 0
b = 0
Next i

AND

CODE 2

For i = 1 To 60 Step 1
If Range("b" & i).Interior.Color = 255 Then
If Range("f" & i) > 0.1 Then
If Range("h" & i) = 26 Or Range("h" & i) = 27 _
Or Range("h" & i) = 28 Or Range("h" & i) = 29 _
Or Range("h" & i) = "50/53" Or Range("h" & i) = "51/53" Then
Range(i & ":" & i).EntireRow.Interior.Color = RGB(255, 255, 0)
End If
End If
End If
Next i
 
Upvote 0

Forum statistics

Threads
1,224,519
Messages
6,179,263
Members
452,902
Latest member
Knuddeluff

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