Advanced Filter Copy to Another Location - Missing Data

gquest

Board Regular
Joined
Feb 20, 2007
Messages
167
Hello,

I'm having an issue with the advanced filter copy to another location function in excel. I have a spreadsheet that has 38 columns and 6,903 rows of data (including two header rows). I wrote a macro to filter and create tabs for all the unique records in column AL. The macro appears to work fine at first: pulls in the correct number of rows, pulls in the first few columns correctly, and even the last few correctly. The issue is the columns in the middle. They aren't getting copied. I tried doing the process manually, without the macro, and I'm having the same issue. Any thoughts? Is there a limit on data (columns and rows)? My code is below.

Thank you in advance for your help!

George

Code:
Option Explicit
Sub DistributeRows()
'this macro creates new sheets based on records in column
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim wsheet As Worksheet
Dim LastRow As Long
Dim LastRowCrit As Long
Dim I As Long

Application.ScreenUpdating = False

    Set wsAll = Worksheets("All")
    LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row - 1
    Set wsCrit = Worksheets.Add
    
    wsAll.Range("al2:al" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True
    
    LastRowCrit = wsCrit.Range("A" & Rows.Count).End(xlUp).Row - 1
    For I = 2 To LastRowCrit
    
        Sheets("Template").Copy After:=Sheets(Sheets.Count)
        Set wsNew = Sheets("Template (2)")
        wsNew.Name = wsCrit.Range("A2")
        wsAll.Rows("2:" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
         CopyToRange:=wsNew.Range("A3"), Unique:=False
        wsCrit.Rows(2).delete
        
    Next I
    
    Application.DisplayAlerts = False
    wsCrit.delete
    Application.DisplayAlerts = True
    
For Each wsheet In Sheets
Select Case wsheet.Name
Case "All", "Template"
'Do Nothing
Case Else
wsheet.Rows(3).delete
End Select
Next wsheet
    
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hello,

I'm having an issue with the advanced filter copy to another location function in excel. I have a spreadsheet that has 38 columns and 6,903 rows of data (including two header rows). I wrote a macro to filter and create tabs for all the unique records in column AL. The macro appears to work fine at first: pulls in the correct number of rows, pulls in the first few columns correctly, and even the last few correctly. The issue is the columns in the middle. They aren't getting copied. I tried doing the process manually, without the macro, and I'm having the same issue. Any thoughts? Is there a limit on data (columns and rows)? My code is below.

Thank you in advance for your help!

George

Code:
Option Explicit
Sub DistributeRows()
'this macro creates new sheets based on records in column
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim wsheet As Worksheet
Dim LastRow As Long
Dim LastRowCrit As Long
Dim I As Long

Application.ScreenUpdating = False

    Set wsAll = Worksheets("All")
    LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row - 1
    Set wsCrit = Worksheets.Add
    
    wsAll.Range("al2:al" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True
    
    LastRowCrit = wsCrit.Range("A" & Rows.Count).End(xlUp).Row - 1
    For I = 2 To LastRowCrit
    
        Sheets("Template").Copy After:=Sheets(Sheets.Count)
        Set wsNew = Sheets("Template (2)")
        wsNew.Name = wsCrit.Range("A2")
        wsAll.Rows("2:" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _
         CopyToRange:=wsNew.Range("A3"), Unique:=False
        wsCrit.Rows(2).delete
        
    Next I
    
    Application.DisplayAlerts = False
    wsCrit.delete
    Application.DisplayAlerts = True
    
For Each wsheet In Sheets
Select Case wsheet.Name
Case "All", "Template"
'Do Nothing
Case Else
wsheet.Rows(3).delete
End Select
Next wsheet
    
    Application.ScreenUpdating = True
    
End Sub


Opps I found the issue. I'm using a two header row system, so the column headers weren't unique were coming up blank.

Please delete this post.
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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