Sub makefaxlist()
Application.EnableEvents = False
Application.ScreenUpdating = False
current_book = ActiveWorkbook.Name
Worksheets("sublist").Activate
current_path = Sheets("info").Cells(10, 5).Value
Do
faxlistname = InputBox("Name of Fax Listing:", "Faxlist Name", "faxlist")
If faxlistname = "" Then Exit Sub
dupfaxlist = False
If Not Range("faxlist").Find(faxlistname, Lookat:=xlWhole) Is Nothing Then
dupfaxlist = True
MsgBox ("A fax listing with that name already exists. Enter a new name.")
End If
Loop Until dupfaxlist = False
Range("faxlist").Cells(Range("faxlist").Count).Offset(0, 1).Value = faxlistname
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "faxlist"
Sheets("sublist").Select
Range(Cells.Find("Name").Address).Select
'Range(Selection, Selection.SpecialCells(xlLastCell)).Select
Sheets("sublist").UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("faxlist").Paste
Application.CutCopyMode = False
Sheets("faxlist").Select
Cells(1, 1).Select
On Error Resume Next
Cells.Find("fax").EntireColumn.Cut
Columns("A:A").Insert Shift:=xlToRight
Cells.Find("name").EntireColumn.Cut
Columns("B:b").Insert Shift:=xlToRight
Cells.Find("contact").EntireColumn.Cut
Columns("c:c").Insert Shift:=xlToRight
Range("d1", Range("A1").SpecialCells(xlLastCell)).EntireColumn.Delete
Cells.Select
Selection.Sort Key1:=Range("a1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Rows(1).Insert
Cells(1, 1).Select
x = 2
'For y = 2 To Range("a1").SpecialCells(xlLastCell).Row
For y = 1 To Sheets("faxlist").UsedRange.Rows.Count
If Cells(x, 1).Value = Cells(x - 1, 1).Value Or IsEmpty(Cells(x, 1)) Then
Rows(x).Delete
Else
x = x + 1
End If
Next
Cells.Select
Cells.EntireColumn.AutoFit
Cells(1, 1).Select
Workbooks(current_book).Sheets("faxlist").Copy
ActiveWorkbook.SaveAs Filename:=current_path + "\" + faxlistname + ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveWindow.Close savechanges:=False
Application.DisplayAlerts = False
Workbooks(current_book).Sheets("faxlist").Delete
Application.DisplayAlerts = True
Workbooks(current_book).Sheets("sublist").Activate
ActiveSheet.Cells(3, 1).Activate
MsgBox ("Faxlist has been created.")
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
current_book = ActiveWorkbook.Name
Worksheets("sublist").Activate
current_path = Sheets("info").Cells(10, 5).Value
Do
faxlistname = InputBox("Name of Fax Listing:", "Faxlist Name", "faxlist")
If faxlistname = "" Then Exit Sub
dupfaxlist = False
If Not Range("faxlist").Find(faxlistname, Lookat:=xlWhole) Is Nothing Then
dupfaxlist = True
MsgBox ("A fax listing with that name already exists. Enter a new name.")
End If
Loop Until dupfaxlist = False
Range("faxlist").Cells(Range("faxlist").Count).Offset(0, 1).Value = faxlistname
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "faxlist"
Sheets("sublist").Select
Range(Cells.Find("Name").Address).Select
'Range(Selection, Selection.SpecialCells(xlLastCell)).Select
Sheets("sublist").UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("faxlist").Paste
Application.CutCopyMode = False
Sheets("faxlist").Select
Cells(1, 1).Select
On Error Resume Next
Cells.Find("fax").EntireColumn.Cut
Columns("A:A").Insert Shift:=xlToRight
Cells.Find("name").EntireColumn.Cut
Columns("B:b").Insert Shift:=xlToRight
Cells.Find("contact").EntireColumn.Cut
Columns("c:c").Insert Shift:=xlToRight
Range("d1", Range("A1").SpecialCells(xlLastCell)).EntireColumn.Delete
Cells.Select
Selection.Sort Key1:=Range("a1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Rows(1).Insert
Cells(1, 1).Select
x = 2
'For y = 2 To Range("a1").SpecialCells(xlLastCell).Row
For y = 1 To Sheets("faxlist").UsedRange.Rows.Count
If Cells(x, 1).Value = Cells(x - 1, 1).Value Or IsEmpty(Cells(x, 1)) Then
Rows(x).Delete
Else
x = x + 1
End If
Next
Cells.Select
Cells.EntireColumn.AutoFit
Cells(1, 1).Select
Workbooks(current_book).Sheets("faxlist").Copy
ActiveWorkbook.SaveAs Filename:=current_path + "\" + faxlistname + ".csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveWindow.Close savechanges:=False
Application.DisplayAlerts = False
Workbooks(current_book).Sheets("faxlist").Delete
Application.DisplayAlerts = True
Workbooks(current_book).Sheets("sublist").Activate
ActiveSheet.Cells(3, 1).Activate
MsgBox ("Faxlist has been created.")
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub