+ Reply to Thread
Results 1 to 23 of 23

VBA to filter by user specified criteria

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    VBA to filter by user specified criteria

    Morning,

    Is it possible to write code so that it filters data specifically on what the user wants to filter by.

    For example.

    If the user specified filter by column 19, GBP?
    Last edited by kenadams378; 08-30-2012 at 07:05 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    How would the user be specifying the criteria?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    by entering a column number and then criteria

    For example

    column = 19
    criteria = GBP.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Where would the criteria be specified?

  5. #5
    Registered User
    Join Date
    08-19-2012
    Location
    Cambodia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA to filter by user specified criteria

    It is possible. You may read this page to get the idea:http://www.worldbestlearningcenter.c...ta-example.htm

  6. #6
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    On a front sheet called 'start'

    Cell A1, A2

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Try this
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Thanks Arlu,

    The following code
    Please Login or Register  to view this content.
    Can you check if this is okay, i get an error message to say subscript out of range

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Subscript out of range has everything to do with the sheet names.

    Just check that your sheet names are named properly and matching with the code in terms of case and spelling.

  10. #10
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    checked and names are okay, the only thing i can think of is that does it need to be Auto Filter Column rather than field?!

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    No the syntax says field.

    You can try recording the code with some temp fields and then change them accordingly to your start sheet fields.

  12. #12
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Still not working, i have attached the workbook here, can you have a look for me, the filter is applied as part of step 1?
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Have you been able to look at my attachment Arlu?

  14. #14
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    In the following line of code i have the error 'object required'

    Any ideas on what the issue is;

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    What is the code before that line?

  16. #16
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Please Login or Register  to view this content.
    What is wb declared as in the dim statements?

  18. #18
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    It is declared as Workbook?

    Dim wb As Workbook

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Can you post your whole code here? It needs a lil change.

  20. #20
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Try this
    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to filter by user specified criteria

    Thanks but i have an error on the same line

    Subscript out of range

    The only sheet this effects is the start sheet and that is named the same as the macro

  23. #23
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA to filter by user specified criteria

    Is it this line that is affected? -
    Please Login or Register  to view this content.
    Does your file have a Sheet1? The file that you are opening through the macro?

+ 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