Может быть что-то вроде этого (использует sub, а не функцию):
Option Explicit
Sub AssignRowValuesToBins()
' Change to whatever your sheet is called. I assume Sheet1.
With ThisWorkbook.Worksheets("Sheet1")
Dim lastRow As Long
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
Dim arrayOfValues() As Variant
arrayOfValues = .Range("C2:DG" & lastRow).Value2
Dim rowIndex As Long
Dim columnIndex As Long
Dim binStat As String
Dim passCount As Long
Dim writeColumnIndex As Long
writeColumnIndex = UBound(arrayOfValues, 2)
For rowIndex = LBound(arrayOfValues, 1) To UBound(arrayOfValues, 1)
binStat = "High"
passCount = 0
For columnIndex = LBound(arrayOfValues, 2) To (writeColumnIndex - 1)
If AreStringsIdentical(arrayOfValues(rowIndex, columnIndex), "Passed") Then
passCount = passCount + 1
If passCount = 2 Then
If AreStringsIdentical(binStat, "High") Then
binStat = "Medium"
passCount = 0
ElseIf AreStringsIdentical(binStat, "Medium") Then
binStat = "Low"
passCount = 0
ElseIf AreStringsIdentical(binStat, "Low") Then
passCount = 0
End If
End If
ElseIf AreStringsIdentical(arrayOfValues(rowIndex, columnIndex), "Failed") Then
passCount = 0
If AreStringsIdentical(binStat, "High") Then
binStat = "High"
ElseIf AreStringsIdentical(binStat, "Medium") Then
binStat = "High"
ElseIf AreStringsIdentical(binStat, "Low") Then
binStat = "Medium"
End If
Else
arrayOfValues(rowIndex, writeColumnIndex) = "Unexpected value '" & arrayOfValues(rowIndex, columnIndex) & "'"
End If
Next columnIndex
arrayOfValues(rowIndex, writeColumnIndex) = binStat
Next rowIndex
.Range("C2").Resize(UBound(arrayOfValues, 1), UBound(arrayOfValues, 2)).Value2 = arrayOfValues
End With
End Sub
Private Function AreStringsIdentical(ByVal firstString As String, ByVal secondString As String) As Boolean
' Performs case-sensitive comparison.
AreStringsIdentical = (VBA.Strings.StrComp(firstString, secondString, vbBinaryCompare) = 0)
End Function