Search Box Macro Script To Search Using Filters In Sheet

Search Box Macro Script To Search Using Filters In Sheet

Hi there,

There are ways to create a search box in excel using a VBA. The main macro code is pasted below.

I was wondering if this could be doable with Zoho sheet. Would this code work? Or, do you guys have a solution to search the sheet and filter the results?

Thanks,
Chad

  1. Sub SearchBox()
    'PURPOSE: Filter Data on User-Determined Column & Text/Numerical value
    'SOURCE: www.TheSpreadsheetGuru.com

    Dim myButton As OptionButton
    Dim SearchString As String
    Dim ButtonName As String
    Dim sht As Worksheet
    Dim myField As Long
    Dim DataRange As Range
    Dim mySearch As Variant

    'Load Sheet into A Variable
      Set sht = ActiveSheet

    'Unfilter Data (if necessary)
      On Error Resume Next
        sht.ShowAllData
      On Error GoTo 0
      
    'Filtered Data Range (include column heading cells)
      Set DataRange = sht.Range("A4:E31") 'Cell Range
      'Set DataRange = sht.ListObjects("Table1").Range 'Table

    'Retrieve User's Search Input
      mySearch = sht.Shapes("UserSearch").TextFrame.Characters.Text 'Control Form
      'mySearch = sht.OLEObjects("UserSearch").Object.Text 'ActiveX Control
      'mySearch = sht.Range("A1").Value 'Cell Input
      
    'Determine if user is searching for number or text
      If IsNumeric(mySearch) = True Then
        SearchString = "=" & mySearch
      Else
        SearchString = "=*" & mySearch & "*"
      End If
        
    'Loop Through Option Buttons
      For Each myButton In sht.OptionButtons
        If myButton.Value = 1 Then
          ButtonName = myButton.Text
          Exit For
        End If
      Next myButton
      
    'Determine Filter Field
      On Error GoTo HeadingNotFound
        myField = Application.WorksheetFunction.Match(ButtonName, DataRange.Rows(1), 0)
      On Error GoTo 0
      
    'Filter Data
      DataRange.AutoFilter _
        Field:=myField, _
        Criteria1:=SearchString, _
        Operator:=xlAnd
      
    'Clear Search Field
      sht.Shapes("UserSearch").TextFrame.Characters.Text = "" 'Control Form
      'sht.OLEObjects("UserSearch").Object.Text = "" 'ActiveX Control
      'sht.Range("A1").Value = "" 'Cell Input
      
    Exit Sub

    'ERROR HANDLERS
    HeadingNotFound:
      MsgBox "The column heading [" & ButtonName & "] was not found in cells " & DataRange.Rows(1).Address & ". " & _
        vbNewLine & "Please check for possible typos.", vbCritical, "Header Name Not Found!"
      
    End Sub

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Slicers are now available in Zoho Sheet—filter your data interactively

                                                At Zoho Sheet, we diligently track user requests and feedback. In line with this, based on extensive user requests, we've integrated Slicers to pivot tables and are delighted to announce its release. Slicers are interactive visual filters that have add,
                                              • Check out the new Checkbox in Zoho Sheet

                                                Checkbox, the simple GUI widget that lets you choose between two mutually exclusive options i.e Yes or No, is now in Zoho Sheet. Having made it across the web, Checkbox is familiar but is still elusive to most spreadsheet software. Special developer ribbons, macros and all other complexities to add a checkbox to a spreadsheet? Not in Zoho Sheet. How to add Checkbox to Zoho Sheet? Adding a Checkbox in Zoho Sheet is simple. Select a cell/range and choose "Checkbox" in "Input Controls" under the Format
                                              • Format and analyze spreadsheet data with Zoho Sheet's Table

                                                While a spreadsheet helps you compile data for easy analysis, formatting helps make your data more comprehensible. We are happy to announce the release of Table, a crucial tool for improving data formatting in Zoho Sheet. More than a formatting tool,
                                              • Introducing Data Bars: Graphically represent changes in data within the cells

                                                Conditional formatting has helped millions of spreadsheet users analyze and highlight their data more efficiently. In addition to the classic rules, color scales, and icon sets available in Zoho Sheet, you can now apply Data Bars, a convenient method
                                              • Zia in Zoho Sheet now makes suggestions on conditional formats, picklists, and checkboxes

                                                Zia, Zoho's popular AI assistant, has been helping users succeed across Zoho applications since inception. In Zoho Sheet, Zia helps users efficiently build reports and analyze data with recommendations about data cleaning, charts, and pivot table. Also,


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now