I got multiple if statements, they check the cells column by column if there is a value "Yes" or "Mediocre". When "Yes" add +1 to the outcome if "Mediocre" add +0.5.
So my problem is as follows: When my code needs to check the next column it needs to do the same but then add +1 or +0.5 to the previous outcome on the same line in the same cell.
This needs to happen on every line.
Eventually when it checked the whole line, the outcome needs to be a percentage: count yes and mediocre then devide by 9 and multiple by 100.
I got an image how it should be below:
I got the code below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("D2:L4"), Range(Target.Address)) Is Nothing Then
'If you add (an)other row(s) edit this code above
Call DeleteP2P4
'If you add (an)other row(s) edit this code above
Call SampleMacro
End If
End Sub
Sub DeleteP2P4()
Range("P2:P4").Select
'If you add (an)other row(s) edit this code above
Selection.ClearContents
End Sub
Sub SampleMacro()
' Get the last row
Dim startRow As Long, lastRow As Long
startRow = 2
lastRow = Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Row
For i = startRow To lastRow
' If there's Yes/Mediocre in D column, then append next number
If Sheet1.Range("D" & i).Value = "Yes" Then
Sheet1.Range("P" & i).Value = "+1"
ElseIf Sheet1.Range("D" & i).Value = "Mediocre" Then
Sheet1.Range("P" & i).Value = "+0.5"
End If
' If there's Yes/Mediocre in E column, then append next number
If Sheet1.Range("E" & i).Value = "Yes" Then
Sheet1.Range("P" & i).Value = "+1"
ElseIf Sheet1.Range("E" & i).Value = "Mediocre" Then
Sheet1.Range("P" & i).Value = "+0.5"
End If
'It continious here with the rest of the If statements
Next
End Sub
Aucun commentaire:
Enregistrer un commentaire