searching more than one criteria with VBA

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

A fellow member very kindly provided me with this code to complete a search from a worksheet named "Result" in cell "A6" and search the data from the worksheet called "Data" from column 15

I want to try and expand on this and be able to search more than one column at the same time

"A6" searches column 15
"B6" searches column 3
"C6" searches column 12

If any of the search cells are blank then ignore

"A6" = "" then don't search with this cell value so you would end up with searching on "B6" and "C6"

If "B6 and C6 was blank then you would only search on "A6"

I hope this makes sense and is possible



Code:
[LEFT][COLOR=#333333][FONT=monospace]Sub Filter_Me_Please()
'Modified  10/21/2018  1:10:18 PM  EDT
Application.ScreenUpdating = False
Dim lastrow As Long
Dim c As Long
Dim s As Variant
Sheets("Data").Activate
c = 15 ' Column Number Modify this to your need
s = Sheets("Result").Range("A6").Value 'Search Value Modify to your need
lastrow = Cells(Rows.Count, c).End(xlUp).Row
With ActiveSheet.Cells(1, c).Resize(lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
    .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Result").Cells(10, "A")
        
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
Application.ScreenUpdating = True
End Sub[/FONT][/COLOR][/LEFT]
 
Glad we could help & thanks for the feedback
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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