This should do it.
Sub Create_Sheets()
Dim fName As String
Application.ScreenUpdating = False
MainFolderPath = "D:\Nadina" & "\"
sn = Sheet1.Cells(1).CurrentRegion.Value
Set dic = CreateObject("scripting.dictionary")
For i = 2 To UBound(sn)
x0 = dic.Item(sn(i, 2))
Next
For j = 0 To dic.Count - 1
fName = dic.keys()(j)
fName = RemoveIllegalCharacters(fName)
With Sheet1
.Cells(1).CurrentRegion.AutoFilter 2, dic.keys()(j)
.AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy Sheets("Temp").Range("A1")
End With
With Sheets("Temp")
With .Cells(1).CurrentRegion
.EntireColumn.AutoFit
.EntireRow.AutoFit
End With
.Copy
End With
With ActiveWorkbook
Sheets(1).Name = fName
.SaveAs MainFolderPath & fName, 51
.Close
End With
Sheets("Temp").Cells(1).CurrentRegion.ClearContents
Next
Sheet1.ShowAllData
Application.ScreenUpdating = True
End Sub
Public Function RemoveIllegalCharacters(ByVal strText As String) As String
Const cstrIllegals As String = "\,/,:,*,?,"",<,>,|,."
Dim lngCounter As Long
Dim astrChars() As String
astrChars() = Split(cstrIllegals, ",")
For lngCounter = LBound(astrChars()) To UBound(astrChars())
strText = Replace(strText, astrChars(lngCounter), "_")
Next lngCounter
RemoveIllegalCharacters = strText
End Function
Bookmarks