+ Reply to Thread
Results 1 to 4 of 4

How to filter specific values entered by user in array

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    25

    How to filter specific values entered by user in array

    I have a table with diferent values. The user has to enter in an inputbox what values must be filtered (several values).

    This is the macro:

    Sub selectaccounts ()
    Dim accounts as string
    accounts = InputBox("Please enter desired accounts separated by comas")
    ActiveSheet.Range("A1:P100").AutoFilter Field:=12, Criteria1:=Array(accounts), Operator:=xlFilterValues
    End sub
    This macro does not work, as the output is empty. I have tried several imputs such as "430, 431, 432" or "430", "431", "432". I have also changed "" by ', but no result either.

    Does anybody know what the format is or how can I solve the problem?

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to filter specific values entered by user in array

    You Have programmed excel to look at column 12. Which column did you intend to look at?

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: How to filter specific values entered by user in array

    Try this and make the entry like this; 430, 431, 432

    Sub selectaccounts()
    Dim accounts As Variant
    accounts = Application.InputBox("Please enter desired accounts separated by comas", Type:=2)
    If accounts = "False" Then Exit Sub 'User canceled
    accounts = Split(accounts, ",")
    ActiveSheet.Range("A1:P100").AutoFilter Field:=12, Criteria1:=accounts, Operator:=xlFilterValues
    End Sub

  4. #4
    Registered User
    Join Date
    10-24-2012
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: How to filter specific values entered by user in array

    Thanks Alpha, very much appreciated.

+ 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