Consulting

Results 1 to 20 of 39

Thread: AutoFilter Percent Values +-5%

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Regular
    Joined
    May 2016
    Posts
    24
    Location
    Attached workbook still have same problem.

    Sub StatTest()
    
    
    Dim wb1         As Workbook, wb2 As Workbook
    Dim ws1         As Worksheet, ws2 As Worksheet
    Dim rng         As range, rng9   As range
    Dim lr          As Long
    Dim MaxValue    As Double
    Dim MinValue    As Double
    
    
    Application.ScreenUpdating = False
    Set wb1 = ActiveWorkbook    'For me:"Book2.xlsm"
    Set ws1 = wb1.Sheets("Sheet1")
    Set wb2 = Workbooks("Book1.xlsm")
    Set ws2 = wb2.Sheets("Sheet1")
    lr = ws2.Cells(Rows.count, "A").End(xlUp).row
    'Set rng = ws2.range("A2:AJ" & lr)
    Set rng = ws2.range("A2:J" & lr)            'Made used range smaller for easier overview. Still same problem.
    Set rng9 = ws1.range("F132:F146")
    rng9.NumberFormat = "0%"                    'To show and make sure rng9 and Col.F have same format.
    ws2.range("F2:F" & lr).NumberFormat = "0%"  'To show and make sure rng9 and Col.F have same format.
    
    
    MaxValue = Application.WorksheetFunction.Max(rng9)
    MaxValue = MaxValue + 0.05
    MinValue = MaxValue - 0.1
    With ws2
        .AutoFilterMode = False
        .range("A1:J1").AutoFilter
        rng.AutoFilter Field:=6, Criteria1:=">=" & MinValue, Operator:=xlAnd, Criteria2:="<=" & MaxValue    'Works for NumberFormat= numbers, not NumberFormat= %
    End With
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by bananas; 09-02-2020 at 05:58 AM.

Tags for this Thread

Posting Permissions

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