VBA Filter Out (Exclude) Value by Input Box

sethae

New Member
Joined
Apr 28, 2010
Messages
8
I am trying to write some VBA in Excel 2007 to filter a list by excluding an item specified by the user in an input box, and then delete the remainder. I've done quite a bit of searching around, and have been able to figure out how to filter the list to the value in the input box, but I want the inverse of that (exclude the item in the input box):

Code:

Dim OfficeLocation As String

uiOfficeLocation = Application.InputBox ("Filter by Office Location", Type:=2)
If uiOfficeLocation = "False" Then Exit Sub: Rem Cancel pressed

Range("A1").Select
Selection.AutoFilter
Selection.Autofilter Field:=1, Criteria1:=uiOfficeLocation

/Code


The examples I've seen where people are trying to filter out a specific value consistently, rather than a user-input value, just add "<>" in front of their value, such as

Criteria1:="<>Main Street"

However this does not seem to work with the input box.

-Seth
 

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