+ Reply to Thread
Results 1 to 5 of 5

Search adding message box

  1. #1
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,726

    Search adding message box

    Hello,

    Can you add a message box when I click "OK" from "Do you want to continue searching for XX" that when I click "OK" but if I am at the last search and it will say "This the end of your search" do you want to "exit" then "OK" "No" so I can start searching again.

    Possbile?

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,735

    Re: Search adding message box

    Your description is unclear with respect to your code. I cannot understand what this means grammatically:
    if I am at the last search and it will say "This the end of your search" do you want to "exit" then "OK" "No" so I can start searching again.
    Your For loop searches in all sheets. Inside the For loop, you have another loop to find all instances in each sheet. If the user answers "OK" to "continue searching" then it continues to search in that sheet, until it finishes and then goes to the next sheet.

    If you want to "start searching again" do you mean to continue to search that sheet? Because that's what it does right now without prompting the user.

    Do you mean to start over again, prompting the user for a new search string? If you do this, then it will abandon any sheets that haven't been searched yet and start a brand new search.

    Or do you want to give the user a chance to exit the entire Sub? That is already done with the first prompt.

    So I'm not clear on the flow you want.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Search adding message box

    This is your current code within the Do...Loop
    PHP Code: 
     If Cell.Address Addx Then Exit Do 

    SHould be:
    PHP Code: 
     If Cell.Address Addx Then 
           
    If MsgBox("This is the end of your search. Do you want to continue?"_
                         vbQuestion 
    vbOKCancel) = vbCancel then   Exit sub 
            
    Exit Do
    end if 
    Quang PT

  4. #4
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,726

    Re: Search adding message box

    Bebo,

    Do I need to keep this code with it or removed it?

    Please Login or Register  to view this content.


    This is what I have now.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Search adding message box

    Like this?
    If it does not work, try to attach sample file.
    PHP Code: 
    Sub FindMe()

        
    Dim Addx    As String
        Dim Cell    
    As Range
        Dim Choice  
    As Integer
        Dim Found   
    As Boolean
        Dim Rng     
    As Range
        Dim State   
    As Long
        Dim What    
    As String
        Dim Wks     
    As Worksheet
        
            
    ' // Input can only be Text
            What = InputBox(Prompt:="Please enter your search criteria", Title:="Search")
            If What = "" Then Exit Sub
            
            For Each Wks In ThisWorkbook.Worksheets
                State = Wks.Visible
                If State <> xlSheetVisible Then Wks.Visible = xlSheetVisible
                DoEvents
                Set Rng = Wks.UsedRange
                Set Cell = Rng.Find(What, Rng.Cells(Rng.Rows.Count, Rng.Columns.Count), xlValues, xlPart, xlByRows, xlNext, False, False, False)
                If Not Cell Is Nothing Then
                    Addx = Cell.Address
                    Found = True
                    Do
                        Cell.Parent.Activate
                        Cell.Select
                        Choice = MsgBox("Do you want to continue searching for """ & What & """?", _
                         vbQuestion + vbOKCancel)
                        '
    Choice MsgBox("Do you want to continue searching?"vbQuestion vbOKCancel)
                        If 
    Choice vbCancel Then Exit Sub
                        Set Cell 
    Rng.FindNext(Cell)
    '-----------
     If Cell.Address = Addx Then 
           If MsgBox("This is the end of your search. Do you want to continue?", _
                         vbQuestion + vbOKCancel) = vbCancel then   Exit sub 
            Exit Do
    end if 
    '
    ---------
                    
    Loop
                End 
    If
                
    Wks.Visible State
            Next Wks
            
            
    If Not Found Then
                MsgBox 
    "No matches were found for """ What """"
            
    End If
            
    End Sub 

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] adding a message box
    By bruno2580 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-14-2017, 10:59 AM
  2. [SOLVED] Adding Wildcard to VBA Search Criteria to Produce a Message Box
    By katkth7533 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 09:26 AM
  3. Replies: 4
    Last Post: 12-02-2014, 05:17 PM
  4. Search column for string and date then search adjacent cell and pop up message
    By ftwobtwo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2014, 09:55 AM
  5. Adding an input message to each cell to bring back corrsponding message
    By Nic31 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2014, 09:28 AM
  6. barcode search in vlookup with pop up message upon successful search
    By tangelag in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-13-2014, 12:25 PM
  7. Adding a message box
    By beberamos in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-22-2013, 03:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1