Consulting

Results 1 to 2 of 2

Thread: Adding filter criteria

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Adding filter criteria

    First post here


    How do I add the criteria such as "greater than" or "less than" to the code below?
    When i recorded the macro, it put in:
    Criteria1:= ">=2"

    but I want the "2" to be replaced by the value in the txtUpperlimit text box

    I assume that I should be declaring the variables somehow but I have got stuck

    [vba]Private Sub Filter_Output()
    Dim upper As Double
    Dim lower As Double
    upper = txtUpperLimit.Value
    lower = txtLowerLimit.Value

    Sheets("Data").Select
    Application.ScreenUpdating = False
    Selection.AutoFilter Field:=8, Criteria1:=upper, Operator:=xlAnd
    Selection.AutoFilter Field:=7, Criteria1:=lower, Operator:=xlAnd
    Cells.Select
    Selection.Copy
    Sheets("Copy").Select

    Range("A1").Select
    ActiveSheet.Paste
    Application.ScreenUpdating = True

    End Sub

    [/vba]
    Last edited by lifeson; 02-17-2007 at 02:57 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Filter_Output()

    Sheets("Data").Select
    Application.ScreenUpdating = False
    Selection.AutoFilter Field:=8, Criteria1:=">=" & txtUpperLimit.Value, Operator:=xlAnd
    Selection.AutoFilter Field:=7, Criteria1:=">=" & txtLowerLimit.Value, Operator:=xlAnd
    Cells.Copy
    Sheets("Copy").Select

    Range("A1").Select
    ActiveSheet.Paste
    Application.ScreenUpdating = True

    End Sub
    [/vba]

    But, after filtering, would you not want only the visible data?

Posting Permissions

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