Hello, I am using the following code in a userform to scan through a worksheet and return some data to it. Typically there will be unique values in each row of column A, but at some point I suppose it could be possible that there may be multiple rows with that same value. Currently the code just loops through to next one each time you click on the "no" button in the msgbox, but I was thinking that it might be beneficial to the user to let them know that there was more than one found. That way if the first one that pops up is not the one that they are looking for, that they need to go to the next one until they find it.
With all that being said I am not sure what would be the best way to do this. Create another separate msgbox letting the user know or is there a way to put a modifier in the existing msgbox that perhaps can tweak the wording in the response (like add in "More than one instance was found, select to go to the next one") if more than one is found. Not sure if there is a way to make the verbiage in a msgbox dynamic or not. Any advice is appreciated - thank you
With all that being said I am not sure what would be the best way to do this. Create another separate msgbox letting the user know or is there a way to put a modifier in the existing msgbox that perhaps can tweak the wording in the response (like add in "More than one instance was found, select to go to the next one") if more than one is found. Not sure if there is a way to make the verbiage in a msgbox dynamic or not. Any advice is appreciated - thank you
VBA Code:
Private Sub FindButton_Click()
Dim ws As Worksheet
Set ws = Sheets("Password Info")
Dim lastRow As Long
lastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
Dim i As Long
Dim found As Boolean
found = False
i = 1
Do While i <= lastRow
If InStr(1, UCase(ws.Cells(i, 1)), UCase(Me.WebSite.Value)) > 0 Then
found = True
Me.WebSite.Value = ws.Cells(i, 1).Value
Me.UserName.Value = ws.Cells(i, 2).Value
Me.PassWord.Value = ws.Cells(i, 3).Value
Dim response As Integer
response = MsgBox("Do you want to change anything?", vbYesNo, "Change Values")
If response = vbYes Then
ws.Cells(i, 2).Value = InputBox("Enter the new username")
ws.Cells(i, 3).Value = InputBox("Enter the new password")
End If
End If
i = i + 1
Loop
If Not found Then
MsgBox "The website is not in the list. Please create your new username and password.", vbExclamation, "Enter Data"
End If
End Sub