Search in 3 columns by textbox with autofilter (excel vba)

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
289
Office Version
  1. 365
Platform
  1. Windows
I don't know if its possible with excel vba. I would like to create 1 textbox that will search from 3 columns. Then it will do auto filter. I hope there is a vba code for that..Thank you very much...
Please see screenshot.



1610089900716.png
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I recommend use a cell instead the textbox .And what would you like to do after filter?

Please paste this code on the sheet module(Right click on the Tab-name and select "V").
Every time you put something on A1, this macro runs automatically.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Long
    If Intersect(Target, Range("A1")) Is Nothing Then
        Exit Sub
    Else
        Range("A6").AutoFilter
        For i = 1 To 3
            Range("A6").AutoFilter field:=i, Criteria1:=Target
            If WorksheetFunction.Subtotal(3, Range(Cells(6, i), Cells(Rows.Count, i).End(xlUp))) > 1 Then
                Exit Sub
            End If
            Range("A6").AutoFilter
        Next
    End If
    MsgBox "no result"
End Sub

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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