Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 563
- Office Version
- 365
- 2010
- Platform
- Windows
I'm aware that the find function doesn't do a multiple criteria search (2 in this case), which I need done, so I declared two range variables so I can individually search for the 2 criterias. The first criteria is located in column "G" and the second is located in column "D". Once the criteria is verified, it offsets a few times in that row to obtain the value of that cell and adds it to the other values found. Once that row is complete I need it to FindNext and check if there are any values there and continue the process until the the end condition is met and then it will exit the loop.
I get the runtime error when the first FindNext appears.
I know that this explanation might be very confusing so I included a large portion of the code to hopefully clarify what I am wanting to achieve.
Thank you
I get the runtime error when the first FindNext appears.
Code:
Set rSearchLotValue = .FindNext(rSearchLotValue)
Thank you
Code:
With ActiveSheet.Range("G:G")
Set rSearchRng = .Find(what:=Me.TextBox4.Value, lookat:=xlWhole, LookIn:=xlValues)
If Not rSearchRng Is Nothing Then
FirstRngCellAddress = rSearchRng.Address
rSearchRng.Select
Do
With ActiveSheet.Range("D:D")
Set rSearchLotValue = .Find(what:=Me.TextBox1.Value, lookat:=xlWhole, LookIn:=xlValues)
If Not rSearchLotValue Is Nothing Then
rSearchLotValue.Select
End If
End With
sProductCodeValue = rSearchRng.Offset(, -5).Value
sSearchLotValue = rSearchRng.Offset(, -3).Value
Do
If rSearchRng.Value = TextBox4.Value And sSearchLotValue = Me.TextBox1.Value And sProductCodeValue = TextBox2.Value Then
rSearchRng.Offset(, -3).Select
lProductTotal = 0
rSearchRng.Offset(, 1).Select
lProductTotal = lProductTotal + rSearchRng.Offset(, 1).Value
rSearchRng.Offset(, 3).Select
lProductTotal = lProductTotal + rSearchRng.Offset(, 3).Value
rSearchRng.Offset(, 5).Select
lProductTotal = lProductTotal + rSearchRng.Offset(, 5).Value
Set rSearchLotValue = .FindNext(rSearchLotValue)
FirstRngCellAddress = rSearchRng.Address
Else
GoTo continue
End If
Loop While rSearchRng.Value = TextBox4.Value And sSearchLotValue = Me.TextBox1.Value And sProductCodeValue = TextBox2.Value And rSearchRng.Address <> FirstRngCellAddress
continue:
Set rSearchRng = .FindNext(rSearchRng)
Loop While Not rSearchRng Is Nothing And rSearchRng.Address <> FirstRngCellAddress
ElseIf rSearchRng Is Nothing Then
MsgBox "The work order number " & frmSDPFLineSelect1.TextBox4.Value & " was not found for the " & sLineName & " line. Please confirm that the correct production line was selected and try again.", vbCritical, "Incorrect Selection"
ActiveWorkbook.Close
frmSDPFLineSelect1.Show
End If
End With
Last edited: