Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 4 of 4

Thread: Use InputBox to return AutoFilter Criteria1

  1. #1
    Join Date
    15th April 2013
    Posts
    3

    Use InputBox to return AutoFilter Criteria1

    Hello, I'm new to the forum and could use some assistance. I'm trying to create a macro to filter data in a range based on user input. I'm not very familiar with InputBox and can't seem to get it to work. The user enters in the producer name and then that should define the criteria1 in the AutoFilter. Below is the section of my macro that I am having problems with. Any help or suggestions would be greatly appreciated.

    VB:
    Selection.AutoFilter 
    Dim strName As String 
     
     
    strName = InputBox(Prompt:="Select Producer", _ 
    Title:="Enter Producer", Default:="Producer Name Here") 
     
     
    If strName = "Producer Name here" Or _ 
    strName = vbNullString Then 
         
         
        Exit Sub 
         
         
    Else 
         
        ActiveSheet.Range("$A$1:$J$69").AutoFilter Field:=8, Criteria1:= _ 
        "=strName", Operator:=xlAnd 
         
    End If 
    
    
    Thank you!

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    26th January 2003
    Location
    Derbyshire,UK
    Posts
    18,506

    Re: Use InputBox to return AutoFilter Criteria1

    No speech marks required around strName

    VB:
    ActiveSheet.Range("$A$1:$J$69").AutoFilter Field:=8, Criteria1:= _ 
    "=" & strName, Operator:=xlAnd 
    
    
    Last edited by cytop; April 15th, 2013 at 16:33. Reason: Corrected code tags
    Hope that Helps

    Roy

    For free Excel tools & articles visit my web site

    If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

  3. #3
    Join Date
    15th April 2013
    Posts
    3

    Re: Use InputBox to return AutoFilter Criteria1

    Thank you Roy! That worked. I knew it had to be something simple, I just couldn't see it.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    26th January 2003
    Location
    Derbyshire,UK
    Posts
    18,506

    Re: Use InputBox to return AutoFilter Criteria1

    I would actually use to allow for changes in the size of the data

    VB:
    ActiveSheet.Range("$A$1").CurrentRegion.AutoFilter Field:=8, Criteria1:= _ 
    "=" & strName, Operator:=xlAnd 
    
    
    Hope that Helps

    Roy

    For free Excel tools & articles visit my web site

    If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Use single VBA input box for multiple inputs
    By doktor in forum EXCEL HELP
    Replies: 2
    Last Post: December 15th, 2011, 20:45
  2. Replies: 13
    Last Post: August 13th, 2010, 16:19
  3. Increment InputBox Number With Each InputBox
    By TanujaJ in forum EXCEL HELP
    Replies: 2
    Last Post: August 24th, 2007, 11:01
  4. Using a userform to return data like a inputbox
    By Zasurus in forum EXCEL HELP
    Replies: 7
    Last Post: November 2nd, 2005, 18:24
  5. Autofilter/VBA Recognize Empty Return
    By shisha1999 in forum EXCEL HELP
    Replies: 2
    Last Post: April 28th, 2005, 06:32

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
  •  
porno