Alternate msgbox

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
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

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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
edit to my previous post... I know that I can influence the verbiage somewhat, referencing a cell value or something, but not sure about a completely alternate line of words. Like saying something such as "3 items found, this is 1 of 3," and then "this is 2 of 3", and then "this is 3 of 3". Not sure if here is a way to do something that different from the original ;)
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top