I have debugged and verified the sheet name is being passed into the function, and that the function is being called. I have verified we enter the while loop. Using message boxes I have verified the data entered by the user and the list the IF statement checks against.
With the data entered, starting from row 4 it will count down. Once its found its match it should pass the row number back to the sub.
- When running the function, I am never prompted with the msgbox message: "the function roLine value is: " inside the IF statement, so I know I am not entering the IF statement. I do however receive msgbox messages set at the beginning of the function and again inside the while loop.
You can see where I can compare the user's input vs the cell its checking against 'shSheet.Cells(roLine, 3)' and yet when they match I still don't enter the IF statement. I don't understand why. While testing I was comparing user entered data of 654 to the value contained in the first cell on my list (also 654).
Copy of Sub -
Sub Find_Customer_Info() Dim shDispatch As Worksheet Dim roLine As Long Dim roScan As Boolean, nameCheck As Boolean, roCheck As Boolean roScan = False nameCheck = True roCheck = True Set shDispatch = ThisWorkbook.Sheets("DISPATCH") If frmUpdateInfo.txtRO <> "" Then roLine = Line_by_RO(shDispatch)'Call CopyFormInfo(roLine) MsgBox "the sub roLine value is: " & roLine End IfEnd Subcopy of the function -
Function Line_by_RO(ByRef shSheet As Worksheet) As Long Dim roLine As Integer Dim roScan As Boolean roScan = False roLine = 4'MsgBox "update form value is: " & frmUpdateInfo.txtRO.Value'MsgBox "the check value is: " & shSheet.Cells(roLine, 3) While roScan = False And roLine < 199 If frmUpdateInfo.txtRO.Value = shSheet.Cells(roLine, 3) Then MsgBox "the function roLine value is: " & roLine Line_by_RO = roLine roScan = True Exit Function End If roLine = roLine + 1 WendEnd Function