lundi 15 avril 2019

Returning text values from if statement which loops through rows

I want to create an if function that returns text values depending on the colour of rows in column D and the percentage in rows in column E. E.g. depending on colour in D6 and value in E6, return a value in F6 and then loop through the rows repeating this. The code I've written runs but no values are appearing anywhere on my excel sheet, can this be resolved?

Sub Message_Click()

Set shr = ActiveWorkbook.Sheets("Report")
shr.Range("F6:F37").ClearContents

Dim rng2 As Range
Dim rng3 As Range
Set rng2 = ActiveSheet.Range("D6:D37")
Set rng3 = ActiveSheet.Range("E6:E37")

For RR 1 To 33
Set rng2 = Cells(RR + 5, 3)
Set rng3 = Cells(RR + 5, 4)

If rng2.Interior.ColorIndex = 50 Then
    Range("F6:F37").Value = "Passed"
ElseIf rng2.Interior.ColorIndex = 38 And rng3 > 60 Then
    Range("F6:F37").Value = "Warning"
ElseIf rng2.Interior.ColorIndex = 38 And rng3 < 60 Then
    Range("F6:F37").Value = "Still has chances"
ElseIf rng2.Interior.ColorIndex = 38 And rng3 = 100 Then
    Range("F6:F37").Value = "Failed"
End If

Next
End Sub

Aucun commentaire:

Enregistrer un commentaire