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
 
So your saying you tried my code as written and it did not work.
Is that what your saying?
The way my code is written it will filter on column 6
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I tried your code and it doesn't work.

It applies the filter on the first column which is Customer CRN and as all values are under 10 million the output is nil .
 
Upvote 0
Are you saying its filtering on column A?

Or are we dealing with a Table and its filtering on column 1 of a Table
 
Upvote 0
It was not the filter but the range . I am using the code as per below and it worked.

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("F4:F" & Lastrow).AutoFilter Field:=1, Criteria1:=">" & ans
End Sub[/CODE]
 
Upvote 0
It was not the filter but the range . I am using the code as per below and it worked.

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("F4:F" & Lastrow).AutoFilter Field:=1, Criteria1:=">" & ans
End Sub[/CODE]
So now your saying the script works. So not sure why 10 minutes ago you said it did not work. So I'm glad you now have it working.
 
Upvote 0
You will want the field to equal 1 because the field value is the offset from your range. Your range is column F. I expect the code provided by "My answer is this" would work.
 
Upvote 0
You may want to use this modified code in case no values are found that match your criteria.
VBA Code:
Sub Filter_Me_Please()
'Modified  12/16/2019  12:23:12 AM  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
ans = Range("F6:F" & Lastrow).SpecialCells(xlCellTypeVisible).count
    If ans < 2 Then
        MsgBox "No Values found"
        Range("F6:F" & Lastrow).AutoFilter
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

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