If you need to organize your marketing list by action plans (Urgent, High, Hib B, Low, Low B, and Low C) and create separate Excel files for each category, the following macro will automate this process for you. Please note, that macOS users may need to grant additional permissions to save files.


Steps


1. Click "Excel" (if you already have the developer tab, go to step 6)



2. Click "Preferences..."



3. Double-click "Formula bar"



4. Click "Developer tab"



5. Click this close button



6. Click "Developer"



7. Click "Visual Basic"



8. Double-click "Sheet1 (Full List)" -> The name of the sheet with all the data should be named "Full List"



9. Click on the editor



10. Paste the macro's code


Sub SplitDataIntoDifferentFiles()
    Dim ws As Worksheet
    Dim LastRow As Long, i As Long, FileRow As Long
    Dim NewBook As Workbook
    Dim UniqueValues As Collection
    Dim Value As Variant
    Dim CellValue As String
    Dim FileName As String
    Dim PathSeparator As String
    
    ' Correctly reference the application's path separator
    PathSeparator = Application.PathSeparator
    
    ' Ensure the workbook contains the "Full list" sheet
    On Error Resume Next
    Set ws = ThisWorkbook.Sheets("Full list")
    On Error GoTo 0
    If ws Is Nothing Then
        MsgBox "Sheet 'Full list' not found!", vbCritical
        Exit Sub
    End If
    
    LastRow = ws.Cells(ws.Rows.Count, "S").End(xlUp).Row
    
    ' Initialize the collection to store unique values
    Set UniqueValues = New Collection
    
    On Error Resume Next
    For i = 2 To LastRow
        CellValue = Trim(ws.Cells(i, "S").Value)
        If CellValue <> "" Then
            ' Attempt to add each unique value to the collection
            UniqueValues.Add CellValue, CStr(CellValue)
        End If
    Next i
    On Error GoTo 0
    
    ' Iterate through each unique value found in column S
    For Each Value In UniqueValues
        Set NewBook = Workbooks.Add
        With NewBook
            ' Copy the header from the original sheet
            ws.Rows(1).Copy Destination:=.Sheets(1).Rows(1)
            FileRow = 2
            
            ' Copy rows corresponding to the current unique value
            For i = 2 To LastRow
                If ws.Cells(i, "S").Value = Value Then
                    ws.Rows(i).Copy Destination:=.Sheets(1).Rows(FileRow)
                    FileRow = FileRow + 1
                End If
            Next i
            
            ' Sanitize the filename
            FileName = Value
            FileName = Replace(FileName, "/", "-")
            FileName = Replace(FileName, "\", "-")
            FileName = Replace(FileName, ":", "-")
            FileName = Replace(FileName, "*", "-")
            FileName = Replace(FileName, "?", "-")
            FileName = Replace(FileName, """", "-")
            FileName = Replace(FileName, "<", "-")
            FileName = Replace(FileName, ">", "-")
            FileName = Replace(FileName, "|", "-")
            
            ' Construct the file path using the system's path separator
            FileName = ThisWorkbook.Path & PathSeparator & FileName & ".xlsx"
            
            ' Attempt to save the new workbook
            On Error Resume Next
            .SaveAs Filename:=FileName
            If Err.Number <> 0 Then
                MsgBox "Failed to save " & FileName, vbCritical
                Err.Clear
            End If
            On Error GoTo 0
            
            ' Close the new workbook without saving changes (since it's already saved)
            .Close SaveChanges:=False
        End With
    Next Value
End Sub


11. Click here (This step may take 3 to 7 minutes, depending on the size of the original file)



12. Check the files.