Solved

VB Help

Posted on 2011-03-13
1
182 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

691 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