+ Reply to Thread
Results 1 to 5 of 5

Add a "Find" Button to Excel (VBA?)

Hybrid View

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Add a "Find" Button to Excel (VBA?)

    This probably sounds stupid because I can just CTRL-F but my other employees are not understanding of Excel. Right now I have macros in my sheet that apparently turn MATCH CASE and MATCH CELL on, and leaves them on.

    So when doing CTRL-F it defaults with both of those on..then you can't find data. I can't determine where this happens to simply turn it off, but I wanted to make a FIND button anyways because they often don't remember how to hit "CTRL-F" either.

    So..simple solution would be a button that just activates a box to type a value and find it without case or cell sensitivity.

    Any pointers? I searched google and here but found nothing like it.

    Thanks in advance.

    Edit
    (Looks like match case saves into the document..explains why it was doing that...woops. Still would like button though)
    Last edited by NewYears1978; 03-25-2014 at 11:01 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Add a "Find" Button to Excel (VBA?)

    Hi..

    Maybe something like this using FindNext..

    Try the attached..

    Private Sub CommandButton1_Click()
        Dim str As String, sh1 As Worksheet, c, x As Long, y As Long
        Set sh1 = Sheets("Sheet1")
        With sh1.Cells
            str = "*" & InputBox("Find Value") & "*"
            Set c = .Find(str, LookIn:=xlValues)
            x = Application.CountIf(sh1.Cells, str)
            y = x - 1
            If Not c Is Nothing Then
                firstaddress = c.Address
                Do
                    Application.Goto c
                    Msgtext = MsgBox("Found: " & x & " Matches" & vbNewLine & vbNewLine & _
                                     "Remaining: " & y & vbNewLine & vbNewLine & "Goto Next?", vbYesNo, "Itterate Through Found Values")
                    If Msgtext = vbNo Then
                        Exit Sub
                    Else
                        GoTo 1
                    End If
    1
                    Set c = .FindNext(c)
                    y = y - 1
                    If y = 0 Then Application.Goto c: Exit Sub
                Loop While Not c Is Nothing And c.Address <> firstaddress
            End If
        End With
    End Sub
    or.. even better .. this will open the Find Dialogue via a CommandButton..

    Private Sub CommandButton2_Click()
     Application.CommandBars("Edit").Controls("Find...").Execute
    End Sub
    Attached Files Attached Files
    Last edited by apo; 03-12-2014 at 06:38 PM.

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Add a "Find" Button to Excel (VBA?)

    Sorry for the late reply, been swamped and not able to work on my forms. Trying this out thank you very much.


    Worked great, thank you
    Last edited by NewYears1978; 03-22-2014 at 01:45 PM.

  4. #4
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Add a "Find" Button to Excel (VBA?)

    Sorry to double post, needed to bring this post back.

    Solution works perfect but I had forgot to ask, when searching I want to ignore columns A and B..is this possible? IN other words only search in columns C+ (or even better if possible search ONLY in column G and J?)

    Thanks in advance..looking at code to see if I can sort it out myself meanwhile

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Add a "Find" Button to Excel (VBA?)

    Hi..

    Sorry for the late reply..

    Private Sub CommandButton1_Click()
        Dim str As String, sh1 As Worksheet, c, x As Long
        Set sh1 = Sheets("Sheet1")
         With sh1.Range("G:G", "J:J")
            str = "*" & Cells(2, 2).Value & "*"
            Set c = .Find(str, LookIn:=xlValues)
             sh1.Cells(2, 3).Value = Application.CountIf(sh1.Range("G:G", "J:J"), str)
            x = sh1.Cells(2, 3).Value
            If Not c Is Nothing Then
                firstaddress = c.Address
                Do
                    Application.Goto c
                    Msgtext = MsgBox("Found: " & sh1.Cells(2, 3).Value & " Matches" & vbNewLine & vbNewLine & _
                    "Remaining: " & x & vbNewLine & vbNewLine & "Goto Next?", vbYesNo, "Itterate Through Found Values")
                    If Msgtext = vbNo Then
                        Exit Sub
                    Else
                        GoTo 1
                    End If
    1
    x = x - 1
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstaddress
            End If
        End With
    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] Emulate Excel 97 getopenfilename "Advanced" find including "Search subfolders"
    By FORTRANguru in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2014, 08:21 PM
  2. Countdown Timer in Excel with a "pause" and "start" button
    By bbhagwat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2013, 05:49 AM
  3. Create a Command Button to "Save As" and "Close" an Excel Workbook
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2013, 05:38 PM
  4. programming code in macro "to find other excel" by clicking a button
    By sanjeev devaliya in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 05-25-2013, 12:11 PM
  5. Replies: 5
    Last Post: 06-26-2006, 09:23 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