Hi Joshi
Try this...if this doesn't fix it I'll need to see your modified file.
Option Explicit
Sub Macro1()
Dim NewBook As Workbook
Dim MyPath As String
Dim Rng As Range
Dim cel As Range
Dim LR As Long
Dim LC As Long
Application.ScreenUpdating = False
MyPath = "C:\joshi"
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Lists").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Worksheets.Add After:=ActiveSheet
ActiveSheet.Name = "Lists"
With Sheets("All_Jobs")
If Not .AutoFilterMode Then
.Range("A1").AutoFilter
End If
LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
' LR = .Range("A" & .Rows.Count).End(xlUp).Row
LC = .Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
.Columns("C:C").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Lists").Range("A1"), Unique:=True
ActiveWorkbook.Names.Add Name:="FLists", RefersTo:= _
"=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
For Each cel In Range("FLists")
If Not FileFolderExists(MyPath & "\" & cel.Value & ".xlsx") Then
Set NewBook = Workbooks.Add
With NewBook
.SaveAs Filename:=MyPath & "\" & cel.Value & ".xlsx"
End With
Else
Workbooks.Open MyPath & "\" & cel.Value & ".xlsx"
Set NewBook = ActiveWorkbook
With NewBook.Sheets("Sheet1")
.Cells.Clear
End With
End If
.Range(.Cells(1, 1), .Cells(LR, LC)).AutoFilter Field:=3, Criteria1:=cel.Value
Set Rng = .AutoFilter.Range
Rng.Resize(Rng.Rows.Count - 1).Copy
NewBook.Sheets("Sheet1").Range("A1").PasteSpecial Paste:=8
NewBook.Sheets("Sheet1").Range("A1").PasteSpecial
NewBook.Close True
Next cel
.AutoFilterMode = False
End With
Application.DisplayAlerts = False
Sheets("Lists").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function
Bookmarks