Dear colleagues,
I've reworked some code I've gotten on Ozgrid :
Sub CalcLSOComplexity()
Dim nRow As Long, r As Long, cnt As Long, rCell As Range
Sheets("Code").Activate
nRow = Range("A" & Rows.Count).End(xlUp).row
For r = 6 To nRow
If sp(Cells(r, "J"), "Vg") And sp(Cells(r, "I"), "") Then
cnt = cnt + 0
Debug.Print cnt
End If
If (sp(Cells(r, "J"), "Vg") And sp(Cells(r, "I"), "Sy")) Or (sp(Cells(r, "J"), "") And sp(Cells(r, "I"), "")) Then
cnt = cnt + 1
Debug.Print cnt
End If
If sp(Cells(r, "I"), "Sy") And (sp(Cells(r, "D"), "D") Or sp(Cells(r, "D"), "Dd")) Then
cnt = cnt + 2
Debug.Print cnt
End If
If sp(Cells(r, "I"), "Sy") And (sp(Cells(r, "D"), "W") Or sp(Cells(r, "F"), "SR") Or sp(Cells(r, "G"), "SI")) Then
cnt = cnt + 3
Debug.Print cnt
End If
Next r
Sheets("Counts").[N32].Value = cnt
cnt = 0
End Sub
Function sp(r As Range, s As String) As Boolean
Dim i As Long, v
sp = False
v = Split(r, ",")
For i = LBound(v) To UBound(v)
If Trim(v(i)) = s Then
sp = True
Exit Function
End If
Next i
End Function
Display More
This to achieve following (input from sheets.("Code")):
1. If (Vg in col J) and (no Sy in col I): Score 0
2. If (Vg in col J and Sy in col I) or (No Vg in col J and no Sy in col I): Score 1
3. If (Sy in col I) with either (D in col D) or (Dd in col D): Score 2
4. If (Sy in col I) with either (W in col D) or ( SR in F) or (SI in G): Score 3
Scores should be calculated for each row
col I and col J have no other input than Sy and Vg, that's why I'm searching for empty cells
I've added the correct score in col T so you can compare, I'm calculating 41 but should get 48 as a total
Problems are:
- Step 2 is not counting and I don't know why
- Each row should get the highest value applicable instead of cnt + x but I don't know how to achieve this
forum.ozgrid.com/index.php?attachment/72233/