pliskers
Active Member
- Joined
- Sep 26, 2002
- Messages
- 462
- Office Version
- 2016
- Platform
- Windows
I'm having a small problem with the code below, which is taking a data range that runs from columns A-AY (beginning in row 1). It's intended to filter on column N, named Route, and paste all rows per route into a separate tab. There are multiple rows containing each route, and the data is sorted by the route column.
The code runs without error, but the data on each tab (while named correctly for each Route) contains the full set of data, not the data filtered on just that route. There must be a small step missing or an incorrect value somewhere.
Would appreciate some assistance with this, please...
The code runs without error, but the data on each tab (while named correctly for each Route) contains the full set of data, not the data filtered on just that route. There must be a small step missing or an incorrect value somewhere.
Would appreciate some assistance with this, please...
VBA Code:
Sub CopyFIlteredData()
Dim r As Integer, route As String, wa As Worksheet
Set ws = ActiveSheet
ws.Range("A1:AY1").AutoFilter
r = 1
Do
r = r + 1
route = ws.Range("N" & r).Value
On Error Resume Next
If Sheets(route) Is Nothing Then
ws.Range("A1:AY1").AutoFilter Field:=14, Criteria:=route
ws.Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add.Name = route
Sheets(route).Paste
ws.ShowAllData
End If
Loop While ws.Range("A" & r + 1).Value <> ""
End Sub
Last edited by a moderator: