Need help with vba code searching using an autofilter

jamespryor

New Member
Joined
Aug 7, 2014
Messages
2
So I have created a spreadsheet where team members can click a button, type in a number, such as 999 into a user form and it will search another sheet that is set up as a table and has an autofilter. I am running into issues with users searching for something that is only one of a kind and then users searching for something that is four of a kind and it only displaying one result.

Example of a one of a kind fee:
Fee code
fee type
other information
other information
other information
100
aaaa
aaaa
aaaa
aaaa

<TBODY>
</TBODY>

Example of a four of a kind fee:

Fee code
fee type
other information
other information
other information
101
abcd
abcd
abcd
abcd
101
abbb
abbb
abbb
abbb
101
accc
accc
accc
accc
101
addd
addd
addd
addd

<TBODY>
</TBODY>

So like I mentioned above if they search the 100 code first it would be fine, but if they then go and search the 101 it would only display the 101/abcd. If the 101 is the first thing they search when they open the sheet everything works fine.

This is the code on the search button of the userform:
Code:
Private Sub SearchButton_Click()
    Range("T6:X11").Clear
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=FeeTextBox.Value
   
    Range("A3:L57").Select
    
    Selection.Copy
    Selection.Name = "ShowFeeInfo"
    Range("RowSourceRange").Select
    ActiveSheet.PasteSpecial
   
    Application.CutCopyMode = False
    
    Unload Me

'centers the userform if they are using two monitors    
With ResultForm1
    .StartUpPosition = 0
    .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
    .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    .Show
End With
      
End Sub

Thank you in advance if you know anyway to help me with this issue!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I don't see you clearing the filter between selections.
Filter #1
Clear Filter
Filter #2

To clear the filter, you set it - but without criteria.
Code:
  ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1
</pre>
 
Upvote 0
Code:
  ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1


Where would this go in the code? I tried placing it before
Code:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=FeeTextBox.Value
but it didn't change anything.

Thank you for your help though!
 
Upvote 0
Then something else is going on... I've played with the data set and cannot reproduce the described issue.
 
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,772
Members
449,187
Latest member
hermansoa

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