Solved

VB Help

Posted on 2011-03-13
1
181 Views
Last Modified: 2012-05-11
Please can you help me convert my spreadsheet?

Currently the text box filters out anything that does not meet the criteria entered into textbox1

I want to include the dropdown box in B3 so that depending on what is selected the code will either work for columns B: K or just the column selected.

search-range-filter.xls
0
Comment
Question by:Gazza83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
wchh earned 500 total points
ID: 35125644
Try the code below...
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim Column As Range
Dim mFilter As Integer
With TextBox1.Parent
    .AutoFilterMode = False
    If Len(TextBox1.Value) > 0 Then
        .[B6:K20].AutoFilter
        For Each Column In .AutoFilter.Range.Columns
           .AutoFilter.Range.Cells(1, 1).AutoFilter Field:=Column.Column - .AutoFilter.Range.Column + 1, Visibledropdown:=False
        Next Column
        mFilter = 1
        Select Case ActiveSheet.Cells(3, 2).Value
            Case "B"
                mFilter = 1
            Case "C"
                mFilter = 2
            Case "D"
                mFilter = 3
            Case "E"
                mFilter = 4
            Case "F"
                mFilter = 5
            Case "G"
                mFilter = 6
            Case "H"
                mFilter = 7
            Case "I"
                mFilter = 8
            Case "J"
                mFilter = 9
            Case "K"
                mFilter = 10
        End Select
        .[B6:K20].AutoFilter Field:=mFilter, Criteria1:="=*" & TextBox1.Value & "*", Operator:=xlAnd
    End If
End With
End Sub

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question