Autofilter code incorrectly selects the wrong value...

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
A userfrom button prompts the user to enter a value in a textbox. The code SHOULD find all values or a single value that meets the the autofilter criteria:
Code:
Dim x As Long
 x = BALS2020.ComboBox1.value ' x = selected value from BALS2020 userform
  Sheets("CREDITCDBALS20").Activate 'CREDITCDBALS20 = sheet Named Range BALANCES2020 is on
  With Range("BALANCES2020")
     .Offset(-1, 0).Resize(.Rows.count + 1).AutoFilter 11, "<=" & x
     .SpecialCells(xlVisible).Copy Sheets("REPORT").Range("A1")
     .AutoFilter
  End With
LOWBALS20.Show 'LOWBALS20 = userform to display autofilter results
Unload BALS2020 'close form
Unload ALLMACROS 'close form
Sheets("BUDGET").Select 'display main form
MAIN SHEET.JPG


highlighted area is just the Named Range BALANCES2020 which changes from week to week(becomes smaller by hiding top row. This Named Range is where autofilter is performed and x or a set of x values is determined.
MAIN SHEET.JPG
SELECTION.JPG

The lowest balance in column 11 is $126.04. When only ONE value from autofilter is found, the result is incorrect as below

RESULT.JPG

This value of $1,685.41 is the very first row of the sheet and is outside the Named Range. This only happens
when the autofilter code finds only ONE value. If it finds multiple values, the code works correctly and all values found are LESS than x, the value to use to find all values less than. I hope I've explained this clearly. It's the code it gives an incorrect result way outside the Named Range when only one value is found.

Can someone help with why it's not performing correctly with a SINGLE autofilter result, but works fine when yielding multiple results all WITHIN the boundaries of the Named Range. Sorry for being long winded. Thanks for anyone's help cr ?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,219
Messages
6,123,681
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top