Hi, I have these VBA code that I run through each range to divide and insert if formula. Initial it has no issue, but now I have new lines, which I do not need to insert the formula if column E (Qty) is empty. And I do not know how to apply the command, if column E is non blank, then apply the rules, into current code to ensure it runs smoothly.
VBA Code:
Sub Dividefast()
Dim w2 As Worksheet
Dim m As Range
Dim lastrow1 As Long
Dim lastm As Long
Application.ScreenUpdating = False
Set w2 = Sheets("DataCompile")
On Error Resume Next
lastrow1 = w2.Cells(Cells.Rows.Count, "A").End(xlUp).Row
lastm = Range("M" & lastrow1).End(xlUp).Row + 1
For Each m In w2.Range("M" & lastm & ":M" & lastrow1)
m.Offset(, 0).Value = m.Offset(, -6) / m.Offset(, -8)
Next
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
VBA Code:
Sub FillYieldGrp()
Dim w2 As Worksheet
Dim LastRow As Long
Dim StartRow As Long
Application.ScreenUpdating = False
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 Double
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