VBA to search for multiple values

burniksapwet

Board Regular
Joined
Oct 6, 2017
Messages
53
Office Version
  1. 2016
Guys I need some help. I need a way to do a filter to where I can just type something like this and get the result 82CL10, 182CL21, 82CM10, 282CM29, 82CM32, 992CS12, 82DT152 and filter just these results. Is this at all possible? I have attached the excel file and a pdf of a sample of what I want it to be. Thank you in advance everyone.

https://www.dropbox.com/s/qnvypuyhhkv9v5z/Book1.xlsx?dl=0
https://www.dropbox.com/s/e4egroarqbms4vn/Book1.pdf?dl=0

I'm not sure if link I made can be viewed by everyone. Please let me know how it turns out. Thank you so much once again.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
If you type your list into cells J1, J2 etc try this
Code:
Sub FilterOnList()

   Dim Ary As Variant

   Ary = Application.Transpose(Range("J1", Range("J" & Rows.Count).End(xlUp)).Value)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:F1").AutoFilter 4, Ary, xlFilterValues
   End With
   
End Sub
 
Upvote 0
If you type your list into cells J1, J2 etc try this
Code:
Sub FilterOnList()

   Dim Ary As Variant

   Ary = Application.Transpose(Range("J1", Range("J" & Rows.Count).End(xlUp)).Value)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:F1").AutoFilter 4, Ary, xlFilterValues
   End With
   
End Sub

Thank you so much sir. The was quick and that was exactly what we need. I hope that you will be willing to help us out update this to a more flexible vba sometime in the future. I will explain the details at a later time. But for now this is exactly what we need. We love it. Thank you.
 
Upvote 0
Glad to help & thanks for the feedback

Hello again Fluff. Thank you for creating this so fast for us. We now have an additional request and hoping you could help out. We were wondering if there is now a way to select which tab we want the filter results to be at? We plan to list all the numbers in A1 or A2 but what we are filtering it too may not always be on the same column. Sometime we would want the filter to be in column B or C or even F or J. Is there a way for you to update the macro that would create a pop up dialog box telling us to select the column we want to filter. I hope this is something that is possible and we would like to thank you in advance. Thank you so much.
 
Upvote 0
Try
Code:
Sub FilterOnList()

   Dim Ary As Variant
   Dim Col As String
   
   Col = InputBox("Please enter a column number")
   If Len(Col) = 0 Then Exit Sub

   Ary = Application.Transpose(Range("J1", Range("J" & Rows.Count).End(xlUp)).Value)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:F1").AutoFilter CLng(Col), Ary, xlFilterValues
   End With
   
End Sub
 
Upvote 0
Try
Code:
Sub FilterOnList()

   Dim Ary As Variant
   Dim Col As String
   
   Col = InputBox("Please enter a column number")
   If Len(Col) = 0 Then Exit Sub

   Ary = Application.Transpose(Range("J1", Range("J" & Rows.Count).End(xlUp)).Value)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:F1").AutoFilter CLng(Col), Ary, xlFilterValues
   End With
   
End Sub

Great job sir. This is perfect. We were just wondering if there is a way to list the column letter instead of the number so that we don't have to count what column we're on. Is this even possible? Thank you once again for all the help. Our group really appreciates it.
 
Upvote 0
Ok, how about
Code:
Sub FilterOnList()

   Dim Ary As Variant
   Dim Col As String
   
   Col = InputBox("Please enter a column number")
   If Len(Col) = 0 Then Exit Sub

   Ary = Application.Transpose(Range("J1", Range("J" & Rows.Count).End(xlUp)).Value)
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("A1:F1").AutoFilter Asc(UCase(Col)) - 64, Ary, xlFilterValues
   End With
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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