Hello,
I have a macro below that currently filters excel data and dumps it into a separate PDF. How can I edit this macro to export the data to another spreadsheet rather than into a PDF?
Thank you
Dim OriginalSheet As Worksheet 'this is just a variable to store the active sheet in case it changes through the process.
Dim AccountNumberSheet As Worksheet 'the name of the sheet we will store our account number list.
Dim UniqueAccountNumberCount As Long 'a count of the number of account numbers in the file.
Dim i As Long 'stores the index for looping.
Dim FilterRangeDef As String 'a string representing the range of cells to be filtered.
Dim FilterRange As Range 'A variable for the range of cells that need to be filtered.
Dim FilterColumn As Integer 'The column you want to filter on. A=1, B=2, C=3 etc.
Dim FileName As String 'The name of the file to be saved.
On Error GoTo cleanup
'********define your filter range here.**********
FilterRangeDef = "A2:AC6261"
FilterColumn = 1
'************************************************
'Start setting some variables and application settings.
Application.EnableEvents = False
Application.ScreenUpdating = False
Set OriginalSheet = ActiveSheet
Set FilterRange = OriginalSheet.Range(FilterRangeDef)
'Add a worksheet for the unique list and copy the unique list in A1
Set AccountNumberSheet = Worksheets.Add
FilterRange.Columns(FilterColumn).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=AccountNumberSheet.Range("A1"), _
CriteriaRange:="", Unique:=True
'Count of the unique values + the header cell
UniqueAccountNumberCount = Application.WorksheetFunction.CountA(AccountNumberSheet.Columns(1))
'If there are unique values start the loop
If UniqueAccountNumberCount >= 1 Then
For i = 2 To UniqueAccountNumberCount
If AccountNumberSheet.Cells(i, 1).Value Like "?*" Then
'Set the filter to the current acocunt
FilterRange.AutoFilter Field:=FilterColumn, _
Criteria1:=AccountNumberSheet.Cells(i, 1).Value
'Create the file name.
FileName = "C:\Notices\parsed\" & AccountNumberSheet.Cells(i, 1).Value & ".pdf"
'export the file to a pdf
On Error Resume Next
OriginalSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=FileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False
On Error GoTo 0
End If
'Close AutoFilter
OriginalSheet.AutoFilterMode = False
Next i
End If
MsgBox "Done"
cleanup:
Application.DisplayAlerts = False
AccountNumberSheet.Delete
Application.DisplayAlerts = True
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
I have a macro below that currently filters excel data and dumps it into a separate PDF. How can I edit this macro to export the data to another spreadsheet rather than into a PDF?
Thank you
Dim OriginalSheet As Worksheet 'this is just a variable to store the active sheet in case it changes through the process.
Dim AccountNumberSheet As Worksheet 'the name of the sheet we will store our account number list.
Dim UniqueAccountNumberCount As Long 'a count of the number of account numbers in the file.
Dim i As Long 'stores the index for looping.
Dim FilterRangeDef As String 'a string representing the range of cells to be filtered.
Dim FilterRange As Range 'A variable for the range of cells that need to be filtered.
Dim FilterColumn As Integer 'The column you want to filter on. A=1, B=2, C=3 etc.
Dim FileName As String 'The name of the file to be saved.
On Error GoTo cleanup
'********define your filter range here.**********
FilterRangeDef = "A2:AC6261"
FilterColumn = 1
'************************************************
'Start setting some variables and application settings.
Application.EnableEvents = False
Application.ScreenUpdating = False
Set OriginalSheet = ActiveSheet
Set FilterRange = OriginalSheet.Range(FilterRangeDef)
'Add a worksheet for the unique list and copy the unique list in A1
Set AccountNumberSheet = Worksheets.Add
FilterRange.Columns(FilterColumn).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=AccountNumberSheet.Range("A1"), _
CriteriaRange:="", Unique:=True
'Count of the unique values + the header cell
UniqueAccountNumberCount = Application.WorksheetFunction.CountA(AccountNumberSheet.Columns(1))
'If there are unique values start the loop
If UniqueAccountNumberCount >= 1 Then
For i = 2 To UniqueAccountNumberCount
If AccountNumberSheet.Cells(i, 1).Value Like "?*" Then
'Set the filter to the current acocunt
FilterRange.AutoFilter Field:=FilterColumn, _
Criteria1:=AccountNumberSheet.Cells(i, 1).Value
'Create the file name.
FileName = "C:\Notices\parsed\" & AccountNumberSheet.Cells(i, 1).Value & ".pdf"
'export the file to a pdf
On Error Resume Next
OriginalSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
FileName:=FileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False
On Error GoTo 0
End If
'Close AutoFilter
OriginalSheet.AutoFilterMode = False
Next i
End If
MsgBox "Done"
cleanup:
Application.DisplayAlerts = False
AccountNumberSheet.Delete
Application.DisplayAlerts = True
With Application
.EnableEvents = True
.ScreenUpdating = True
End With