PDA

View Full Version : Solved: How to create autofilter code using Textbox Userform?



genracela
05-20-2010, 05:40 PM
I've been addicted to VBA since joining this forum.

I already learned how to write VBA codes for my formulas and calculations, lookup from 1 workbook to another then copy paste data, cell splitting etc etc...

And right now I'm into using userform.

I have a file(attached), an I want to do an autofilter using VBA. I already put my userform, but the problem is, I don't know how to start the idea that I have in mind.

In the userform, I want to type in the search criteria(criterias on B6="code"), then it will just automatically filter if I click on the "SEARCH BUTTON", then Clear the UserForm(not the data) when I click on "Clear"

Thanks!

mbarron
05-20-2010, 06:22 PM
Does this do what you want?

Sub FilterB6()
If UCase(Range("B6").Value) <> "ALL" Then
Range("A6").AutoFilter Field:=2, Criteria1:=Sheets("Sheet1").TextBox1.Value
Else
If ActiveSheet.AutoFilterMode Then
Range("A6").AutoFilter
End If
End If
End Sub


Sub ClearFilter()
If ActiveSheet.AutoFilterMode Then
Range("A6").AutoFilter
End If
Sheets("Sheet1").TextBox1.Value = ""
End Sub

Just for clarification. You are using ActiveX controls, not a User Form. User forms are created in the VBE.

genracela
05-20-2010, 06:29 PM
:SHOCKED:
This is just exactly what I wanted to do!!! I've been thinking about it since yesterday, and you replied in less than an hour

:jawdown:

:super: Thanks!!!!Thanks!!! Thanks!!!

genracela
05-21-2010, 01:01 AM
With project continuation on this thread:
http://www.vbaexpress.com/forum/showthread.php?t=32225