bobsburgers
Board Regular
- Joined
- Jun 25, 2017
- Messages
- 60
Hi, All!
Whenever I hit press the "Cancel" button on the dialogue box, the worksheet still seems to run the function while searching for nothing.
I'm not sure if it's an issue with the working in VBA, or an issue with the dialogue box, but I haven't been able to find a solution.
Below is the code:
Please let me know if I can provide you with any more information - thank you!!
Best,
Bob
Whenever I hit press the "Cancel" button on the dialogue box, the worksheet still seems to run the function while searching for nothing.
I'm not sure if it's an issue with the working in VBA, or an issue with the dialogue box, but I haven't been able to find a solution.
Below is the code:
Code:
Sub Item_Return()
Dim scanstring As String
Dim foundscan As Range
Dim ws As Worksheet
Dim foundscan_address As String
Set ws = ActiveSheet
scanstring = InputBox("Please enter a value to search for", "Enter value")
With ws.Columns("D")
Set foundscan = .Find(What:=scanstring, LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not foundscan Is Nothing Then
foundscan_address = foundscan.Address
Do
foundscan.Offset(0, 4).Value = scanstring
ws.Activate
foundscan.Activate
ActiveWindow.ScrollRow = foundscan.Row
Set foundscan = .FindNext(foundscan)
Loop While Not foundscan Is Nothing And foundscan.Address <> foundscan_address
Else
MsgBox scanstring & " was not found"
End If
End With
End Sub
Please let me know if I can provide you with any more information - thank you!!
Best,
Bob