+ Reply to Thread
Results 1 to 3 of 3

Setting a text box value in a filter

Hybrid View

perbags Setting a text box value in a... 07-20-2010, 05:11 AM
Richard Buttrey Re: Setting a text box value... 07-20-2010, 05:32 AM
perbags Re: Setting a text box value... 07-20-2010, 05:55 AM
  1. #1
    Registered User
    Join Date
    06-17-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    Setting a text box value in a filter

    Can anyone help me with this please.

    I am setting up a filter and what I need is the value from a text box that is entered to be searched in column C, This is the code I come up with so far but I cant get it to work..

    Thanks for your help.

    Perbags

    Private Sub CommandButton1_Click()
    
    
     Dim Site As String
        
        TextBox1.Text = Site
        
      Sheets("Sitedata").Select
       Range("A2").Select
       Range("2:2000").AutoFilter 3, "<>(Site)"
          
    
    End Sub
    Last edited by perbags; 07-20-2010 at 05:57 AM. Reason: solved!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Setting a text box value in a filter

    Hi,

    Try:

    Dim stSite As String
    
    stSite = UserForm1.TextBox1
    Sheets("Sitedata").Range("2:2000").AutoFilter 3, "<>" & stSite
    Note. Avoid selecting and activating cells, this is rarely needed and only slows things down. You'd also be better advised to name the range 2:2000, probably with a dynamic name and use the name in the code. That will avoid problems should you ever add any rows above row 2. Change the 'UserForm1' form name if necessary.

    HTH
    Last edited by Richard Buttrey; 07-20-2010 at 05:34 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-17-2010
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Setting a text box value in a filter

    Thanks Richard

    This works great, very much appreciated

    Regards

    Perbags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1