Sort out named range in VBA

opislak

Board Regular
Joined
Feb 28, 2017
Messages
68
Hello,

Is it possible in VBA to sort a list which excludes names from a named range?

I have a list of names, which includes blanks, a department, a code, and a number of coworkers that don't have to be taken into consideration. Therefore, I would like to blind these data.
In my code, the sorting works fine without the named range part (criteria 3). The names-list is too long and volatile, so I would prefer not to hard code the names to be excluded. I put them in a Named Range, called "Excluded" on a separate tab.
This is a relevant part of my code so far (the Criteria3:="<>" & excl does not work. It gives "Run-time error '1004': Application-defined or object-defined error")
VBA Code:
Sub Sort()

Dim excl As String

        Set excl = ThisWorkbook.Names("Excluded")
        With Range("A1", Cells(lastRow, lastCol)).Select
            Selection.AutoFilter Field:=1, Criteria1:="<>" '(Blanks)
            Selection.AutoFilter Field:=2, Criteria1:="<>*ICT", Criteria2:="<>GA00*", Criteria3:="<>" & excl
        End With

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,979
Messages
6,122,560
Members
449,089
Latest member
Motoracer88

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