Hi, I have the data sheet "DataCompile", which I tried to use if...else if to return value into column M, if the criteria in column N is met. However, no matter how I change the coding, it will not return other value, and only return the largest value, which is "60%><=100% Yield".
What should I do to rectify the coding below, so that it can populate every cell with correct value, that is meeting the criteria?
What should I do to rectify the coding below, so that it can populate every cell with correct value, that is meeting the criteria?
VBA Code:
Sub FillIF()
Application.ScreenUpdating = False
Dim w2 As Worksheet
Dim LastRow As Long
Dim StartRow As Long
Set w2 = Sheets("DataCompile")
On Error Resume Next
LastRow = w2.Cells(w2.Rows.Count, 1).End(xlUp).Row
StartRow = w2.Cells(w2.Rows.Count, 14).End(xlUp).Row + 1
Dim i As Long
Dim Yield As Long
Dim Result As String
For i = StartRow To LastRow
Yield = w2.Range("M" & i).Value
If Yield > 0.6 And Yield <= 1 Then
Result = "60%><=100% Yield"
ElseIf Yield > 0.3 And Yield <= 0.6 Then
Result = "=<60% Yield"
Else
Result = "=<30% Yield"
End If
w2.Range("N" & i).Value = Result
Next
Application.ScreenUpdating = True
End Sub
Attachments
Last edited: