Filter a column for a userinput value

amrita17170909

Board Regular
Joined
Dec 11, 2019
Messages
74
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hi All,

I am trying to build a code which will accept a user input for the filter.

So for example if userinput = 10,000 the code is going to only show the values over 10,000.

I also want the range to be dynamic but I am not sure how to incorporate that

Sub AutoFilter_range()

'Filter to show values over 10 Million
Application.ScreenUpdating = False

'Dim Range_to_filter As Range
'Dim UserInputValue As Long

UserInputValue = InputBox("Please enter value in millions.", , 10)

Set Range_to_filter = Range("F6:f178")

Range_to_filter.AutoFilter Field:=6, Criteria1:="UserInputvalue"

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try removing the quotation marks around the criteria1 variable.
 
Upvote 0
Try this:
VBA Code:
Sub Filter_Me_Please()
'Modified  12/12/2019  10:15:58 PM  EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "F").End(xlUp).Row
Dim ans As Long
ans = InputBox("Please enter value in millions.", , 10)
ActiveSheet.Range("F6:F" & Lastrow).AutoFilter Field:=1, Criteria1:=">" & ans
End Sub
 
Upvote 0
Thanks for your help.

But I am that new to the forum that I dont know how to say which response helped!

The code worked previously but now I am getting the following error " Autofilter method of Range Class Failed"

Any ideas?
 
Upvote 0
You posted your code and I posted my code.
So I'm not sure what code your now saying is creating a error.
 
Upvote 0
The below code is not working. I have slightly tweaked it.

Sub AutoFilter_range()
'Modified 12/12/2019 10:15:58 PM EST

Dim Lastrow As Long

Lastrow = Cells(Rows.Count, "F").End(xlUp).Row

Dim ans As Long

ans = InputBox("Please enter value in millions.", , 10)

ActiveSheet.Range("F6:F" & Lastrow).AutoFilter Field:=6, Criteria1:=">" & ans


End Sub
 
Upvote 0
Why did you tweak my code?
If I provide code you need why do you feal it needs to be tweaked

The script want's to search Column F

You changed 1 to 6
 
Last edited:
Upvote 0
I had to tweak the code because the filter has to be applied on the value column of the sheet which is column 6 and not column 1 as per my original code.

If I use auto filter 1 the code will work but it is not the output I am looking for . The filter over 10 million has to be applied on column 6 to get the correct output.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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