+ Reply to Thread
Results 1 to 4 of 4

Using a VBA code to sort a table

  1. #1
    Registered User
    Join Date
    11-21-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    2

    Using a VBA code to sort a table

    Please help. I have a table of employees that I need to filter based on their labor grade. I am able to filter them by only one labor grade as of right now. What I need is to filter them by multiple labor grades (27, 29, 31, 32, 33, 34, 35, 36). So far, I have this code:

    Sub Table()
    Application.ScreenUpdating = False

    If [C29] = 27 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "27"
    Sheets("Splash Screen").Select
    End If

    If [C30] = 29 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "29"
    Sheets("Splash Screen").Select
    End If

    If [C31] = 31 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "31"
    Sheets("Splash Screen").Select
    End If

    If [C32] = 32 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "32"
    Sheets("Splash Screen").Select
    End If

    If [C33] = 33 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "33"
    Sheets("Splash Screen").Select
    End If

    If [C34] = 34 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "34"
    Sheets("Splash Screen").Select
    End If

    If [C35] = 35 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "35"
    Sheets("Splash Screen").Select
    End If

    If [C36] = 36 Then
    Sheets("Results").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
    "36"
    Sheets("Splash Screen").Select
    End If
    End Sub[/FONT]





    Is there anyway that I can link these together so I can select multiple labor grades? Example: 27, 35 and 36? Any help would be extremely appreciated. Thanks.

  2. #2
    Registered User
    Join Date
    04-30-2009
    Location
    Spain
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: Using a VBA code to sort a table

    You might order the table from smallest (27) to biggest (36) and them sort using a range from >=27 to <=36 but that would work only for the values in the range not for values only in the extremes.

  3. #3
    Registered User
    Join Date
    04-30-2009
    Location
    Spain
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: Using a VBA code to sort a table

    You can use different criteria as well like

    Criteria1:="=27", _
    Operator:=xlOr, Criteria2:="=36"
    but don't know how many you can use.

  4. #4
    Registered User
    Join Date
    11-21-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Using a VBA code to sort a table

    dvb,
    Going off of your criteria suggestion, how would you place that in the code I inserted above?

+ 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