I am working on a sub of a larger set of code and when testing this one piece, I get the error Next without For. I have looked, every For has a Next, every If has End If and every While has a Wend.
Can you help me figure this out?
Thanks in advance!
Option Explicit
Sub trueTotal()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1") 'be more explicit than 'ActiveSheet
Dim sPart As String
Dim SearchRange As Range
Dim FindRow As Range
Dim ReturnRowNumber As Integer
Dim currPickTotal As Integer
Dim totalPick As Integer
Dim scanRow As Integer
Dim scanQty As Integer
Dim cell As Range
Dim rng As Range
Set FindRow = Nothing
'Compare the range and loop until equal
While ws.Range("E6:E30") <> ws.Range("F6:F30")
Set rng = ws.Range("E6:F30")
For Each cell In rng
If Not cell Is Empty Then
ws.Range(rng).Interior.ColorIndex = 4
Next cell
While FindRow Is Nothing
sPart = InputBox("Scan the first part number", "Part Number") 'Get Part Number
'Set the search range to get the cell row for the part number.
Set SearchRange = ws.Range("A6", ws.Range("A30").End(xlUp))
Set FindRow = SearchRange.Find(sPart, LookIn:=xlValues, LookAt:=xlWhole)
If Not FindRow Is Nothing Then ReturnRowNumber = FindRow.Row
Wend
scanRow = ReturnRowNumber
'Error checking to ensure scanned amount is not greater than required amount
If totalPick <= ws.Range("E" & scanRow) Then
scanQty = InputBox("Scan the Quantity", "Quantity") 'Get Quantity
currPickTotal = ws.Range("F" & scanRow).Value
totalPick = currPickTotal + scanQty
Range("F" & scanRow).Value = totalPick
Set FindRow = Nothing
If Range("E" & scanRow).Value = Range("F" & scanRow).Value Then
Range("E" & cell.Row).Interior.ColorIndex = 3
Range("F" & cell.Row).Interior.ColorIndex = 3
End If
Else
scanQty = InputBox("Scan exceeds the required Quantity, please scan a lower quantity.", "Quantity") 'Get Quantity
currPickTotal = ws.Range("F" & scanRow).Value
currPickTotal = currPickTotal - scanQty 'Subtract last scanQty
totalPick = currPickTotal + scanQty
Range("F" & scanRow).Value = totalPick
Set FindRow = Nothing
If Range("E" & scanRow).Value = Range("F" & scanRow).Value Then
Range("E" & cell.Row).Interior.ColorIndex = 3
Range("F" & cell.Row).Interior.ColorIndex = 3
End If
End If
Wend
End Sub
End IfbeforeNext cellWhile ws.Range("E6:E30") <> ws.Range("F6:F30")won't work.Ifstatement into one line